setlevels: Set levels of a factor object

Description Usage Arguments Value Author(s) Examples

View source: R/call.R

Description

A function to set levels of a factor object.

Usage

1
setlevels(x, old=levels(x), new, skip_absent=FALSE)

Arguments

x

A factor object.

old

A character vector containing the factor levels to be changed. Default is levels of x.

new

The new character vector containing the factor levels to be added.

skip_absent

Skip items in old that are missing (i.e. absent) in 'names(x)'. Default FALSE halts with error if any are missing.

Value

Returns an invisible and modified factor object.

Author(s)

Morgan Jacob

Examples

1
2
3
x = factor(c("A", "A", "B", "B", "B", "C")) # factor vector with levels A B C
setlevels(x, new = c("X", "Y", "Z"))        # set factor levels to: X Y Z
setlevels(x, old = "X", new = "A")          # set factor levels X to A

kit documentation built on March 9, 2021, 5:12 p.m.

Related to setlevels in kit...