| 1 |
\name{dimrename} |
| 2 |
\alias{dimrename} |
| 3 |
\alias{colrename} |
| 4 |
\alias{rowrename} |
| 5 |
\title{Change dimnames, rownames, or colnames} |
| 6 |
\description{ |
| 7 |
These functions provide an easy way to change the \code{dimnames}, \code{rownames} or \code{colnames} of |
| 8 |
an array. |
| 9 |
} |
| 10 |
\usage{ |
| 11 |
dimrename(x, dim = 1, \dots, gsub = FALSE, fixed = TRUE, warn = TRUE) |
| 12 |
rowrename(x, \dots, gsub = FALSE, fixed = TRUE, warn = TRUE) |
| 13 |
colrename(x, \dots, gsub = FALSE, fixed = TRUE, warn = TRUE) |
| 14 |
} |
| 15 |
\arguments{ |
| 16 |
\item{x}{An array with dimnames} |
| 17 |
\item{dim}{A vector that indicates the dimensions} |
| 18 |
\item{\dots}{A sequence of named arguments} |
| 19 |
\item{gsub}{a logical value; if TRUE, \code{\link{gsub}} is used to change the |
| 20 |
\code{dimnames} of the object. |
| 21 |
That is, instead of substituting whole names, substrings of the |
| 22 |
\code{dimnames} of the object can changed. |
| 23 |
} |
| 24 |
\item{fixed}{a logical value, passed to \code{\link{gsub}}. If TRUE, |
| 25 |
substitutions are by fixed strings and not by regular expressions.} |
| 26 |
\item{warn}{logical; should a warning be issued if the pattern is not found?} |
| 27 |
} |
| 28 |
\details{ |
| 29 |
\code{dimrename} changes the dimnames of \code{x} along dimension(s) \code{dim} according to the |
| 30 |
remaining arguments. The argument names are the \emph{old} |
| 31 |
names, the values are the new names. |
| 32 |
\code{rowrename} is a shorthand for changing the rownames, |
| 33 |
\code{colrename} is a shorthand for changing the colnames of a matrix |
| 34 |
or matrix-like object. |
| 35 |
|
| 36 |
If \code{gsub} is FALSE, argument tags are the \emph{old} |
| 37 |
\code{dimnames}, the values are the new \code{dimnames}. |
| 38 |
If \code{gsub} is TRUE, arguments are substrings of the \code{dimnames} |
| 39 |
that are substituted by the argument values. |
| 40 |
|
| 41 |
} |
| 42 |
\value{ |
| 43 |
Object \code{x} with changed dimnames. |
| 44 |
} |
| 45 |
|
| 46 |
\examples{ |
| 47 |
m <- matrix(1,2,2) |
| 48 |
rownames(m) <- letters[1:2] |
| 49 |
colnames(m) <- LETTERS[1:2] |
| 50 |
m |
| 51 |
dimrename(m,1,a="first",b="second") |
| 52 |
dimrename(m,1,A="first",B="second") |
| 53 |
dimrename(m,2,"A"="first",B="second") |
| 54 |
|
| 55 |
rowrename(m,a="first",b="second") |
| 56 |
colrename(m,"A"="first",B="second") |
| 57 |
|
| 58 |
# Since version 0.99.22 - the following also works: |
| 59 |
|
| 60 |
dimrename(m,1,a=first,b=second) |
| 61 |
dimrename(m,1,A=first,B=second) |
| 62 |
dimrename(m,2,A=first,B=second) |
| 63 |
} |
| 64 |
|
| 65 |
\keyword{manip} |