Debian Codegraph @

man/relabel.Rd

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