Although order
will order a vector, and it is possible to order several columns of a data.frame by specifying each column individually in the call to order, dfOrder
will order a dataframe by as many columns as desired.
dfOrder(object, columns,absolute=FALSE)
The data.frame to be sorted
Column numbers to use for sorting. If positive, then they will be sorted in increasing order. If negative, then in decreasing order
If TRUE, then sort the absolute values
The original data frame is now in sorted order.
This is just a simple helper function to reorder data.frames. Originally developed to organize IRT output from the ltm package. It is a basic add on to the order function.
(Completely rewritten for version 1.8.1.)
Other useful file manipulation functions include read.file
to read in data from a file or read.clipboard
from the clipboard, fileScan
, filesList
, filesInfo
, and fileCreate
dfOrder
code is used in the test.irt
function to combine ltm and sim.irt
output.
# NOT RUN {
x <- data.frame(matrix(sample(1:4,64,replace=TRUE),ncol=4))
dfOrder(x) # sort by all columns
dfOrder(x,c(1,4)) #sort by the first and 4th column
dfOrder(x,c(1,-2)) #sort by the first in increasing order,
#the second in decreasing order
# }
Run the code above in your browser using DataLab