This function wraps relevelsByNamedVec
for named vector and
relevelsByNotNamedVec
for not named vectors
A factor or a character string vector that will be cast into factor
A named vector or unnamed vector.
Actions taken in case existing levels are missing: 'pass', 'warning', or 'error'.
Actions taken in case unrecognised levels are found: 'pass', 'warning', or 'error'.
A vector of factor
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"))))