Possible Duplicate:
How to sort a dataframe by column(s) in R
everyone:
I want to sort the data within groups using R. For example:
the data is:
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
This is the original data. Please copy and use the code as follows:
read.table("clipboard",strip.white=T,header=T)
And then, what should I do? After sorted, I want the result to be this:
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
You can use
plyrandarrange. All you are doing is ordering first by one column, then the next(on second looking, your example output does not quite make sense. How are you getting a combination of
CL1002 PREDICTED: