[R] Sorting in R
Peter Dalgaard BSA
p.dalgaard at biostat.ku.dk
Wed Jun 21 17:56:22 CEST 2000
Jim Robison-Cox <jimrc at gauss.math.montana.edu> writes:
> On Wed, 21 Jun 2000, Art Salwin wrote:
>
> > Having secondary keys to break ties would be nice, as would
> > the ability to sort (in this example)
> > all 3 vectors at once.
>
> 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.
Indeedy:
spsheet[order(name,age,zip),]
Two things (well really the same thing) that R is not good at:
(a) sorting descending
(b) alternate collating sequence
(a) works for numeric vectors (order(-x)) but not character. One might
consider having an ordering-function argument, defaulting to "<"
--
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list