我有一个称为的数据框mydf
。列中有重复的样本Sample
。我想提取具有最大值的唯一样本行total_reads
并获取result
。
mydf<-structure(list(Sample = c("AOGC-02-0188", "AOGC-02-0191", "AOGC-02-0191",
"AOGC-02-0191", "AOGC-02-0194", "AOGC-02-0194", "AOGC-02-0194"
), total_reads = c(27392583, 19206920, 34462563, 53669483, 24731988,
43419826, 68151814), Lane = c("4", "5", "4", "4;5", "5", "4",
"4;5")), .Names = c("Sample", "total_reads", "Lane"), row.names = c("166",
"169", "170", "171", "173", "174", "175"), class = "data.frame")
结果
Sample total_reads Lane
AOGC-02-0188 27392583 4
AOGC-02-0191 53669483 4;5
AOGC-02-0194 68151814 4;5
你可以aggregate
,然后merge
,
merge(aggregate(total_reads ~ Sample, mydf, max), mydf)
# Sample total_reads Lane
#1 AOGC-02-0188 27392583 4
#2 AOGC-02-0191 53669483 4;5
#3 AOGC-02-0194 68151814 4;5
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句