% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/sortit.R
\name{sortit}
\alias{sortit}
\title{Sort an Object according to the Keys}
\usage{
sortit(x, ..., descending = 0, cols = NULL)
}
\arguments{
\item{x}{an object to be sorted.\cr
If x is a matrix, all the column will be sorted.}

\item{...}{vectors to be uses as keys.\cr
Must be the same length as x.}

\item{descending}{= 1 to sort descendingly when ... is present.\cr}

\item{cols}{vector consisting of the column numbers of x
which will be used as keys.\cr
This has priority over ... .}
}
\value{
Object of the same size as x.
}
\description{
Sort an Object according to the Keys
}
\details{
In order to sort descendingly using cols argument,
 specify negative column number in cols= \cr
or use - sign in numeric ... ariguments. \cr
Or, use descending=1 option.
}
\examples{
# 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 ) )
colnames(X)=c("xx1","xx2")
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
set.seed(1701)
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) )

}
