dae (version 3.0-32)

fac.recode: Recodes factor levels using values in a vector. The values in the vector do not have to be unique.

Description

Recodes the levels and values of a factor using each value in the newlevels vector to replace the corresponding value in the vector of levels of the factor.

Usage

fac.recode(factor, newlevels, ...)

Arguments

factor

The factor to be recoded.

newlevels

A vector of length levels(factor) containing values to use in the recoding.

...

Further arguments passed to the factor call creating the new factor.

Value

A factor.

See Also

as.numfac and mpone in package dae, factor, relevel.

Examples

Run this code
# NOT RUN {
## set up a factor with labels
a <- factor(rep(1:4, 4), labels=c("A","B","C","D"))
 
## recode "A" and "D" to 1 and "B" and "C" to 2
b <- fac.recode(a, c(1,2,2,1), labels = c("a","b"))
# }

Run the code above in your browser using DataCamp Workspace