DATA MINING
Desktop Survival Guide by Graham Williams |
|||||
To sort a matrix on two columns us the order function:
x <- rep(rbinom(5, size=4, prob=.5), 6) y <- rnorm(30) df <- data.frame(x=x, y=y) df <- df[order(df$x, df$y),] |
To reverse sort on the second sort column:
df <- df[order(df$x, -df$y),] |
For dealing with missing values in a sort, see http://www.ats.ucla.edu/STAT/r/faq/sort.htm.