如何在R中按组折叠数据帧中未成对元素的值

如何在R中按组折叠数据帧中未成对元素的值,r,dataframe,collapse,R,Dataframe,Collapse,给定一个包含4列的数据框(我的数据框包含大约40个基因) 某些规格: 柱“样本”可以删除,因为它只显示未配对的每组的基因出现数量。 非常感谢您的建议aggregate(count~gene+group,my_df,sum) library(dplyr) my_df %>% group_by(gene, group) %>% summarise(count = sum(count)) count gene group 0.3 gene1 exp 0.9 gen

给定一个包含4列的数据框(我的数据框包含大约40个基因)

某些规格: 柱“样本”可以删除,因为它只显示未配对的每组的基因出现数量。 非常感谢您的建议

aggregate(count~gene+group,my_df,sum)
library(dplyr)
my_df %>% group_by(gene, group) %>% 
    summarise(count = sum(count))
count   gene    group
0.3 gene1   exp
0.9 gene1   cnt
0.8 gene2   exp
0.5 gene2   cnt
library(dplyr)
my_df %>% group_by(gene, group) %>% 
    summarise(count = sum(count))