Hi there,
Could anybody help me on how to sort a dataframe by one variable in the
dataframe?
Thank you
Lisa Wang
Princess Margaret Hospital
Toronto, Ca
tel: 416 946 4501
__
R-help@stat.math.ethz.ch mailing list
Lisa Wang wrote:
Hi there,
Could anybody help me on how to sort a dataframe by one variable in the
dataframe?
Thank you
See ?order.
x - data.frame(a = runif(10), b = 1:10)
x[order(x$a), ]
--sundar
__
R-help@stat.math.ethz.ch mailing
Try RSiteSearch(Sort data frame).
Anyhow, use order() or sort.list() as follows:
dat[order(dat[,'myColumn']),]#Sorts data.frame dat by column myColumn
dat-dat[sort.list(dat$myColumn, decreasing = T),] #Another option to do the
same. You can specify decreasing or increasing within both function