1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
\name{relabel}
\alias{relabel}
\alias{relabel.default}
\alias{relabel.factor}
\alias{relabel4}
\alias{relabel4,item-method}
\title{Change labels of factors or labelled objects}
\description{
Function \code{relabel} changes the labels of a factor or any object
that has a \code{names}, \code{labels}, \code{value.labels}, or \code{variable.labels} attribute.
Function \code{relabel4} is an (internal) generic which is called by \code{relabel}
to handle S4 objects.
}
\usage{
\method{relabel}{default}(x, \dots, gsub = FALSE, fixed = TRUE, warn = TRUE)
\method{relabel}{factor}(x, \dots, gsub = FALSE, fixed = TRUE, warn = TRUE)
\S4method{relabel4}{item}(x, \dots)
# This is an internal method, see details.
# Use relabel(x, \dots) for 'item' objects
}
\arguments{
\item{x}{An object with a \code{names}, \code{labels}, \code{value.labels}, or \code{variable.labels} attribute}
\item{\dots}{A sequence of named arguments, all of type character}
\item{gsub}{a logical value; if TRUE, \code{\link{gsub}} is used to change the
labels of the object. That is, instead of substituting whole labels, substrings of the
labels of the object can changed.}
\item{fixed}{a logical value, passed to \code{\link{gsub}}. If TRUE,
substitutions are by fixed strings and not by regular expressions.}
\item{warn}{a logical value; if TRUE, a warning is issues if a
a change of labels was unsuccessful.}
}
\details{
This function changes the names or labels of \code{x} according to the
remaining arguments.
If \code{gsub} is FALSE, argument tags are the \emph{old}
labels, the values are the new labels.
If \code{gsub} is TRUE, arguments are substrings of the labels
that are substituted by the argument values.
Function \code{relabel} is S3 generic. If its first argument is an S4 object,
it calls the (internal) \code{relabel4} generic function.
}
\value{
The object \code{x} with new labels defined by the \dots arguments.
}
\examples{
f <- as.factor(rep(letters[1:4],5))
levels(f)
F <- relabel(f,
a="A",
b="B",
c="C",
d="D"
)
levels(F)
f <- as.item(f)
labels(f)
F <- relabel(f,
a="A",
b="B",
c="C",
d="D"
)
labels(F)
# Since version 0.99.22 - the following also works:
f <- as.factor(rep(letters[1:4],5))
levels(f)
F <- relabel(f,
a=A,
b=B,
c=C,
d=D
)
levels(F)
f <- as.item(f)
labels(f)
F <- relabel(f,
a=A,
b=B,
c=C,
d=D
)
labels(F)
}
\keyword{manip}
|