| 1 |
\name{reorder.array} |
| 2 |
\alias{reorder} |
| 3 |
\alias{reorder.array} |
| 4 |
\alias{reorder.matrix} |
| 5 |
\title{Reorder an Array or Matrix} |
| 6 |
\description{ |
| 7 |
\code{reorder.array} reorders an array along a specified |
| 8 |
dimension according given names, indices or results of |
| 9 |
a function applied. |
| 10 |
} |
| 11 |
\usage{ |
| 12 |
\method{reorder}{array}(x,dim=1,names=NULL,indices=NULL,FUN=mean,...) |
| 13 |
\method{reorder}{matrix}(x,dim=1,names=NULL,indices=NULL,FUN=mean,...) |
| 14 |
} |
| 15 |
\arguments{ |
| 16 |
\item{x}{An array} |
| 17 |
\item{dim}{An integer specifying the dimension along which \code{x} should be ordered.} |
| 18 |
\item{names}{A character vector} |
| 19 |
\item{indices}{A numeric vector} |
| 20 |
\item{FUN}{A function that can be used in \code{apply(x,dim,FUN)} } |
| 21 |
\item{...}{further arguments, ignored.} |
| 22 |
} |
| 23 |
\details{ |
| 24 |
Typical usages are |
| 25 |
\preformatted{ |
| 26 |
reorder(x,dim,names) |
| 27 |
reorder(x,dim,indices) |
| 28 |
reorder(x,dim,FUN) |
| 29 |
} |
| 30 |
|
| 31 |
The result of \code{rename(x,dim,names)} is \code{x} |
| 32 |
reordered such that \code{dimnames(x)[[dim]]} is equal to |
| 33 |
the concatenation of those elements of \code{names} |
| 34 |
that are in \code{dimnames(x)[[dim]]} and the remaining elements |
| 35 |
of \code{dimnames(x)[[dim]]}. |
| 36 |
|
| 37 |
The result of \code{rename(x,dim,indices)} is \code{x} |
| 38 |
reordered along \code{dim} according to \code{indices}. |
| 39 |
|
| 40 |
The result of \code{rename(x,dim,FUN)} is \code{x} |
| 41 |
reordered along \code{dim} according to \code{order(apply(x,dim,FUN))}. |
| 42 |
|
| 43 |
} |
| 44 |
|
| 45 |
\value{ |
| 46 |
The reordered object \code{x}. |
| 47 |
} |
| 48 |
\seealso{ |
| 49 |
The default method of \code{\link[stats:reorder.factor]{reorder}} in package \code{stats}. |
| 50 |
} |
| 51 |
\examples{ |
| 52 |
(M <- matrix(rnorm(n=25),5,5,dimnames=list(LETTERS[1:5],letters[1:5]))) |
| 53 |
reorder(M,dim=1,names=c("E","A")) |
| 54 |
reorder(M,dim=2,indices=3:1) |
| 55 |
reorder(M,dim=1) |
| 56 |
reorder(M,dim=2) |
| 57 |
} |
| 58 |
\keyword{manip} |