大家: 我想使用R对组内的数据进行排序。例如: 数据是:
geneID Nr.annotation
CL1002 uncharacterized
CL1002 uncharacterized
CL1002 uncharacterized
CL1002 uncharacterized
CL1002 uncharacterized
CL1002 uncharacterized
CL1019 PREDICTED:
CL1019 PREDICTED:
CL1019 predicted
CL1019 PREDICTED:
CL1019 PREDICTED:
CL1019 predicted
CL1019 predicted
CL1019 hypothetical
CL10246 unnamed
CL10246 predicted
CL10246 unnamed
CL10246 unnamed
CL10246 unnamed
CL10246 unnamed
CL10246 unnamed
CL1064 octicosapeptide/Phox/Bem1p
CL1064 octicosapeptide/Phox/Bem1p
CL1064 serine/threonine
CL1064 serine/threonine
CL1064 serine/threonine
CL1064 serine/threonine
这是原始数据。请复制并使用以下代码:
read.table("clipboard",strip.white=T,header=T)
然后,我该怎么办?排序后,我希望结果如下:
geneID Nr.annotation
CL1002 PREDICTED:
CL1002 uncharacterized 4
CL1019 PREDICTED: 6
CL1019 hypothetical 1
CL1019 uncharacterized 1
CL10246 predicted 1
CL10246 unnamed 6
CL1064 octicosapeptide/Phox/Bem1p 2
CL1064 serine/threonine 4
答案 0 :(得分:1)
您可以使用plyr
和arrange
。您所做的只是首先按一列排序,然后是下一个
library(plyr)
arrange(DF,geneID, Nr.annotation)
(第二眼看,你的示例输出没有多大意义。你是如何得到
的组合 CL1002 PREDICTED: