Possible Duplicate:
How to sort a dataframe by column(s) in R
I was just wondering if some one could help me out, I have what I thought should be a easy problem to solve.
I have the table below:
SampleID           Cluster
R0132F041p          1
R0132F127           1
R0132F064           1
R0132F068p          1
R0132F015           2
R0132F094           3
R0132F105           1
R0132F013           2
R0132F114           1
R0132F014           2
R0132F039p          3
R0132F137           1
R0132F059           1
R0132F138p          2
R0132F038p          2
and I would like to sort/order it by Cluster to get the results as below:
SampleID    Cluster
R0132F041p  1
R0132F127   1
R0132F064   1
R0132F068p  1
R0132F105   1
R0132F114   1
R0132F137   1
R0132F059   1
R0132F015   2
R0132F013   2
R0132F014   2
R0132F138p  2
R0132F038p  2
R0132F094   3
R0132F039p  3
I have tried the following R code:
data<-read.table('Table.txt', header=TRUE,row.names=1,sep='\t')
data <- data.frame(data)
data <- data[order(data$Cluster),]
write.table(data, file = 'OrderedTable.txt', append = TRUE,quote=FALSE, sep = '\t', na ='NA', dec = '.', row.names = TRUE, col.names = FALSE)
and get the following output:
1   1
2   1
3   1
4   1
5   1
6   1
7   1
8   1
9   2
10  2
11  2
12  2
13  2
14  3
15  3
Why have the SampleIDs been replaced by the numbers 1-15 and what do these numbers represent, I have read the ?order() page however this seems to explain sort.list better than order() if any one could help me out on this I would be very grateful.
 
     
     
    