Skip to content
Prev 6183 / 398498 Next

Sorting in R

On Wed, 21 Jun 2000, Art Salwin wrote:

            
For brevity, I'd make these into a data frame:
 spsheet <- data.frame(name,age,zip)
name(order(zip))
or
spsheet[order(zip),]
name(order(age))
or
spsheet[order(age),]
That's a bit harder,  I would sort first on the secondary column, then
the primary.  Or tertiary - secondary - primary.

 If primary is name, secondary age, tertiary zip:
spsheet <- spsheet[order(zip),]
spsheet <- spsheet[order(age),]
spsheet[order(name),]
 
  I hope someone has a better way.
Jim Robison-Cox               ____________    
Department of Math Sciences  |            |       phone: (406)994-5340
2-214 Wilson Hall             \   BZN, MT |       FAX:   (406)994-1789
Montana State University       |  *_______|
Bozeman, MT 59717-2400          \_|      e-mail: jimrc at math.montana.edu 


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._