Description Usage Arguments Author(s) See Also Examples
Function to sort a matrix or data frame by the value in a column. On exit the function displays the sorted data. Any NAs in the sort column are sorted to beyond the greatest value. If the function is run as temp <- gx.sort(x, ncol)
the sorted data are not displayed, but retained in temp
for subsequent use or display.
1 |
x |
the matrix or data frame to be sorted. |
col |
a column number, the value of which will be used to sort the matrix or data frame |
reverse |
the default is to sort in ascending order of the value in column |
Robert G. Garrett
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | ## Make test data available
data(sind)
attach(sind)
## Sort data frame sind into ascending order on the value
## of column 4, Zn
gx.sort(sind, 4)
## Sort data frame sind into descending order on the value
## of column 4, Zn
gx.sort(sind, 4, reverse = TRUE)
## Sort only the geochemical data in data frame sind into
## descending order on the value of column 4, Zn. Note
## that sind[, -c(1:3)] moves the old column 4 to
## position 1
gx.sort(sind[, -c(1:3)], 1, reverse = TRUE)
## Detach test data
detach(sind)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.