| 1 |
\name{uniqueL} |
| 2 |
\alias{uniqueL} |
| 3 |
\title{A Reversable Version of unique()} |
| 4 |
\description{ |
| 5 |
A version of \code{\link{unique}} keeping enough information to |
| 6 |
reverse (or \emph{invert}) to the original data. |
| 7 |
} |
| 8 |
\usage{ |
| 9 |
uniqueL(x, isuniq = !duplicated(x), need.sort = is.unsorted(x)) |
| 10 |
} |
| 11 |
\arguments{ |
| 12 |
\item{x}{numeric vector, of length \code{n}, say.} |
| 13 |
\item{isuniq}{logical vector of the same length as \code{x}. For the |
| 14 |
reversion to work this should select at least all unique values of |
| 15 |
\code{x}.} |
| 16 |
\item{need.sort}{logical indicating if \code{x} is not yet sorted. |
| 17 |
Note that this argument exists only for speedup possibility when it |
| 18 |
is known, and that it \emph{must be set correctly}.} |
| 19 |
} |
| 20 |
\value{ |
| 21 |
list of two components, |
| 22 |
\item{ix}{integer vector of indices} |
| 23 |
\item{xU}{vector of values from \code{x}} |
| 24 |
such that both \code{x[isuniq] === xU} and \code{xU[ix] === x}. |
| 25 |
} |
| 26 |
\author{Martin Maechler} |
| 27 |
\seealso{\code{\link{Duplicated}} from the \pkg{sfsmisc} package in |
| 28 |
addition to the standard \code{\link{unique}} and |
| 29 |
\code{\link{duplicated}}. |
| 30 |
} |
| 31 |
\examples{ |
| 32 |
x0 <- c(1:3,2:7,8:4) |
| 33 |
str(r0 <- uniqueL(x0)) |
| 34 |
with(r0, xU[ix]) ## == x0 ! |
| 35 |
\dontshow{ |
| 36 |
for(n in 1:100) { |
| 37 |
x0 <- round((1+rpois(1,lam=1))*rnorm(40)) |
| 38 |
r0 <- uniqueL(x0) |
| 39 |
stopifnot(sort(unique(x0)) == r0$xU, |
| 40 |
with(r0, xU[ix]) == x0) |
| 41 |
} |
| 42 |
} |
| 43 |
} |
| 44 |
\keyword{utilities} |