relabel: Change labels of factors or labelled objects

Description Usage Arguments Details Value Examples

Description

Function relabel changes the labels of a factor or any object that has a names, labels, value.labels, or variable.labels attribute.

Usage

1
2
3
4
## Default S3 method:
relabel(x, ..., gsub = FALSE, fixed = TRUE, warn = TRUE)
## S3 method for class 'factor'
relabel(x, ..., gsub = FALSE, fixed = TRUE, warn = TRUE)

Arguments

x

An object with a names, labels, value.labels, or variable.labels attribute

...

A sequence of named arguments, all of type character

gsub

a logical value; if TRUE, 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.

fixed

a logical value, passed to gsub. If TRUE, substitutions are by fixed strings and not by regular expressions.

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 x according to the remaining arguments. If gsub is FALSE, argument tags are the old labels, the values are the new labels. If gsub is TRUE, arguments are substrings of the labels that are substituted by the argument values.

Value

The object x with new labels defined by the ... arguments.

Examples

1
2
3
4
5
6
7
8
9
  f <- as.factor(rep(letters[1:4],5))
  levels(f)
  F <- relabel(f,
    a="A",
    b="B",
    c="C",
    d="D"
    )
  levels(F)

mutils documentation built on May 2, 2019, 4:44 p.m.

Related to relabel in mutils...