[R] Sorting a data set

tony.anderson tony.anderson at noaa.gov
Thu May 31 00:07:06 CEST 2012


I am a novice user of R and am stumbling on how to order a dataset 
produced during my session.

I have a 1863 row X 14 column dataset that I want to put out to a file.  
I want the output sorted by the first column and then by the second 
column both in ascending order.  The first column is character and the 
second is numeric (I hope).  I used an "as.numeric" function to assign 
that variable.  Is there a reason R would not accept "0" or "00" as a 
numeric value?

I have tried using the order function but the examples I have seen don't 
seem to translate for me.  I tried something like this assuming my 
dataset is called "data".

datanew<-data[order(var1, var2),]
print(datanew)

This generates an "incorrect number of dimensions"  error in the order 
function.  I also tried listing all the variables in the parentheses.

Your help is appreciated.



More information about the R-help mailing list