Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I order a dataframe by the second column in R?
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/1296646/how-to-sort-a-dataframe-by-columns-in-r">How to sort a dataframe by column(s) in R</a> </p> </blockquote> <p>I was just wondering if some one could help me out, I have what I thought should be a easy problem to solve.</p> <p>I have the table below:</p> <pre><code>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 </code></pre> <p>and I would like to sort/order it by <strong>Cluster</strong> to get the results as below:</p> <pre><code>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 </code></pre> <p>I have tried the following R code: </p> <pre><code>data&lt;-read.table('Table.txt', header=TRUE,row.names=1,sep='\t') data &lt;- data.frame(data) data &lt;- 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) </code></pre> <p>and get the following output:</p> <pre><code>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 </code></pre> <p>Why have the <strong>SampleIDs</strong> been replaced by the numbers 1-15 and what do these numbers represent, I have read the <code>?order()</code> page however this seems to explain <strong>sort.list</strong> better than <strong>order()</strong> if any one could help me out on this I would be very grateful.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload