relevels: Relevel a factor by a named or unnamed vector.

Description Usage Arguments Value See Also Examples

View source: R/factor.R

Description

This function wraps relevelsByNamedVec for named vector and relevelsByNotNamedVec for not named vectors

Usage

1
2
3
4
5
6
relevels(
  x,
  refs,
  missingLevels = c("pass", "warning", "error"),
  unrecognisedLevels = c("warning", "pass", "error")
)

Arguments

x

A factor

refs

A named vector or unnamed vector.

missingLevels

Actions taken in case existing levels are missing: 'pass', 'warning', or 'error'.

unrecognisedLevels

Actions taken in case unrecognised levels are found: 'pass', 'warning', or 'error'.

Value

A vector of factor

See Also

relevelsByNamedVec and relevelsByNotNamedVec

Examples

1
2
3
4
5
6
7
oldFactor <- factor(c("A", "B", "A", "C", "B"), levels=LETTERS[1:3])
refLevels <- c("B", "C", "A")
refDict <- c("A"="a", "B"="b", "C"="c")
newFactor <- relevels(oldFactor, refLevels)
stopifnot(identical(newFactor, factor(c("A", "B", "A", "C", "B"), levels=c("B", "C", "A"))))
newFactor2 <-  relevels(oldFactor, refDict)
stopifnot(identical(newFactor2, factor(c("a", "b", "a", "c", "b"), levels=c("a", "b", "c"))))

ribiosUtils documentation built on March 13, 2020, 2:54 a.m.