[R] multicolumn sort on dataframe?

Spencer Graves spencer.graves at pdf.com
Fri Mar 26 17:44:55 CET 2004


?order

Jeff D. Hamann wrote:

>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
>
>______________________________________________
>R-help at stat.math.ethz.ch mailing list
>https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>  
>




More information about the R-help mailing list