输入
函数
hebing = function(df)
{
plist = unique(df$fam)
# 合并行,相同sample
df2 = data.frame(apply(df[df$fam==plist[1], 2:ncol(df)], 2, sum))
colnames(df2)[1] = plist[1]
for(i in 2:length(plist))
{
tmp = apply(df[df$fam==plist[i], 2:ncol(df)], 2, sum)
df2 = cbind(df2, tmp)
colnames(df2)[i] = plist[i]
}
df2 = data.frame(t(df2))
return(df2)
}
df_merge = hebing(df_fam)
输出
网友评论