Description Usage Arguments Details Value Author(s) Examples
Sorts a dataframe by one or more variables, ascending or
descending The order of the arguments form
and
dat
is interchangeable. In the formula, use + for
ascending, - for decending. Sorting is left to right in the
formula. For example, to sort the dataframe Oats
with sorting variables Block
and Variety
,
useage is either of the following:
1 2 | sort.data.frame(form, dat)
sort.data.frame(dat, form)
|
form |
A formula with the variable names to use for sorting |
dat |
The dataframe to sort |
sort.data.frame(~ Block - Variety, Oats)
or
sort.data.frame(Oats, ~ - Variety + Block)
The sorted dataframe
Kevin Wright with ideas from Any Liaw and small edits by Landon Sego
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | d <- data.frame(b=factor(c("Hi","Med","Hi","Low"),levels=c("Low","Med","Hi"),
ordered=TRUE),
x=c("A","D","A","C"),y=c(8,3,9,9),z=c(1,1,1,2))
# Sort by descending z, descending b
sort.data.frame(~-z-b,d)
# Sort by ascending x, ascending y, and ascending z
sort.data.frame(~x+y+z,d)
# Sort by descending x, ascending y, ascending z
sort.data.frame(~-x+y+z,d)
# Sort by ascending x, descending y, ascending z
sort.data.frame(d,~x-y+z)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.