sortit {}R Documentation

Sort an Object according to Keys


Sort an Object according to Keys


sortit(x, ..., descending = 0, cols = NULL)



an object to be sorted.
If x is a matrix, all the column will be sorted.


voctors to be uses as keys.
Must be the same length as x.


= 1 to sort descendingly when ... is present.


vector consisting of the column numbers of x which will be used as keys.
This has priority over ... .


In order to sort descendingly using cols argument, specify negative column number in cols=
or use - sign in numeric ... ariguments.
Or, use descending=1 option.


Object of the same size as x.


# sort the rows of x according to the order of ... .
sortit( demomat(4,2), c(4,3,1,2) )
sortit( demomat(4,2), c(4,3,1,2), c("a","a","b","b") )

# sort the rows of x using the colums specified in cols= as keys.
sortit( diag(4), cols=1:4 )

# sorting the rows of a matrix
X <- as.matrix( expand.grid( 1:2, 3:5 ) )
sortit( X, cols=c(1,2) )
Print( sortit( X, cols=c(1,-2) ), sortit( X, X[,1], -X[,2] ) )

# the last column first or the first column first.
Print( sortit( X, cols=1:2 ), sortit( X, cols=2:1 ) )

# sort the result of unique function
Y <- matrix( sample(letters[1:3],99, replace=1),,3 )
Yu <- unique(Y)
Print( Yu, sortit(Yu, cols=1:3) )
Print( sortit(Yu, Yu[, 1], Yu[, 2], Yu[, 3]) )
Print( Yu, sortit(Yu, cols=-(1:3)) )
Print( sortit(Yu, Yu[, 1], Yu[, 2], Yu[, 3], descending=1) )

[Package version 0.1.3 Index]