[R] a R function for sort a data frame.

TEMPL Matthias Matthias.Templ at statistik.gv.at
Fri Apr 1 16:19:02 CEST 2005


Hi,

x <- data.frame(A=rnorm(10), B=round(runif(10,0,10)), C=rnorm(10))

#one way:

#increasing order
x.sort.in <- x[order(x$B),] 
x.sort.in

#decreasing order:
x.sort.de <- x[rev(order(x$B)),] 
x.sort.de

Best,
Matthias


> -----Ursprüngliche Nachricht-----
> Von: r-help-bounces at stat.math.ethz.ch 
> [mailto:r-help-bounces at stat.math.ethz.ch] Im Auftrag von Mario Morales
> Gesendet: Freitag, 01. April 2005 05:23
> An: r-help at stat.math.ethz.ch
> Betreff: [R] a R function for sort a data frame.
> 
> 
> Is there a R function for sort a data frame by a variable ?
> 
> I know sort a vector, but I don't know sort a data frame by a 
> column. Can you help me ?
> 
> the sort() function don't  work with data frame.
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list 
> https://stat.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