[R] sorting & subsetting a data.frame

Liviu Andronic landronimirc at gmail.com
Sun Mar 6 23:49:03 CET 2011


Dear all
This may be obvious, but I cannot get it working. I'm trying to subset
& sort a data frame in one go.
x <- iris
x$Species1 <- as.character(x$Species)
##subsetting alone works fine
with(x, x[Sepal.Length==6.7,])
##sorting alone works fine
with(x, x[order(Sepal.Length, rev(sort(Species1))),])
##gets subsetted, but not sorted as expected
with(x, x[(Sepal.Length==6.7) & order(Sepal.Length, rev(sort(Species1))),])
##gets subsetted, but sorts very strangely
xa <- with(x, x[Sepal.Length==6.7,]); with(xa, xa[order(Sepal.Length,
rev(sort(Species1))),])
xa <- with(x, x[Sepal.Length==6.7,]); with(xa, xa[order(rev(sort(Species1))),])

I've checked The R Inferno, Quick-R and several other places with no
obvious solution.

Any ideas? Regards
Liviu


-- 
Do you know how to read?
http://www.alienetworks.com/srtest.cfm
http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader
Do you know how to write?
http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail



More information about the R-help mailing list