Description Usage Arguments Value See Also Examples
This function wraps relevelsByNamedVec
for named vector and
relevelsByNotNamedVec
for not named vectors
1 2 3 4 5 6 |
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'. |
A vector of factor
relevelsByNamedVec
and
relevelsByNotNamedVec
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"))))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.