[R] multicolumn sort on dataframe?

Jeff D. Hamann jeff.hamann at forestinformatics.com
Fri Mar 26 17:34:36 CET 2004


I couldn't find any reference to this in the FAQ, but is it possible to sort
a dataframe by multiple columns?

I've created some code, similar to the following:

nspr.code <- sp.results$sp.code[order( sp.results$sp.code )]
nspr.tpa <- sp.results$tpa[order( sp.results$sp.code )]

nspr.code <- as.character( levels( nspr.code ) )[nspr.code]
nspr.tpa <- as.numeric( levels( nspr.tpa ) )[nspr.tpa]

hope <- as.data.frame( cbind( nspr.code, as.numeric(nspr.tpa) ) )

and it seems to work, but I have dataframes that I would like to sort on
using multiple columns (numeric and character). Something like :

newframe <- sort( data=frame, list=c(plot,plant,sp) )

Or am I just barking up the wrong tree?

Jeff.


---
Jeff D. Hamann
Forest Informatics, Inc.
PO Box 1421
Corvallis, Oregon USA 97339-1421
541-754-1428
jeff.hamann at forestinformatics.com
www.forestinformatics.com




More information about the R-help mailing list