% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/order2.R
\name{order2}
\alias{order2}
\title{Returns a permutation which rearranges its first argument in the order
 specified by the second argument.}
\usage{
order2(x, order = NULL, descending = 0)
}
\arguments{
\item{x}{a vector to be sorted according to order}

\item{order}{a vector containing the definition of the sort order \cr
If order is not given, this function returns the same as the native order.}

\item{descending}{= 1 to sort descendingly}
}
\value{
The permutation vector, \code{od}, to be used as:\cr
\code{ x_sorted <- x[od] }
}
\description{
Returns a permutation which rearranges its first argument in the order
 specified by the second argument.
}
\details{
The returning value, od, will be calculated as: \cr\cr
\code{  df1 <- data.frame( id1=1:length(x), x ) } \cr
\code{  df2 <- data.frame( id2=1:length(order), order ) } \cr
\code{  temp <- merge( df1, df2, by.x="x", by.y="order", all=1 ) } \cr
\code{  temp <- temp[order(temp$id2),] } \cr
\code{  od <- (temp$id1)[1:length(x)] } \cr
}
\examples{
order <- c("B", "D", "A", "C", "E","X")
x <- c( "A", "D", "B", "E", "C", "D", "A" )
od <- order2( x, order )
Print( x, order, od, x[od] )

}
