-5

可能重复:
如何在 R 中按列对数据框进行排序

大家:我想使用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
4

1 回答 1

1

您可以使用plyrarrange。您所做的只是先按一列排序,然后再按下一列

library(plyr)

arrange(DF,geneID, Nr.annotation)

(在第二次查看时,您的示例输出不太有意义。您如何获得以下组合

CL1002 PREDICTED:

于 2012-11-15T03:03:44.940 回答