## set up a factor with labels
Treats <- factor(rep(1:4, 4), labels=letters[1:4])
## recast to reduce the levels: "a" and "d" to 1 and "b" and "c" to 2, i.e. from 4 to 2 levels
A <- fac.recast(Treats, newlevels = c(1,2,2,1), labels = letters[1:2])
A <- fac.recast(Treats, newlevels = letters[c(1,2,2,1)])
#reduce the levels from 4 to 2, with re-ordering the levels vector without changing the values
#of the new recast factor vector
A <- fac.recast(Treats, newlevels = letters[c(1,2,2,1)], levels.order = letters[2:1])
#reassign the values in the factor vector without re-ordering the levels attribute
A <- fac.recast(Treats, newlevels = letters[4:1])
#reassign the values in the factor vector, with re-ordering the levels attribute
A <- fac.recast(Treats, newlabels = letters[4:1])
#reorder the levels attribute with changing the values in the factor vector
A <- fac.recast(Treats, levels.order = letters[4:1])
#reorder the values in the factor vector without changing the levels attribute
A <- fac.recast(Treats, newlevels = 4:1, newlabels = levels(Treats))
Run the code above in your browser using DataLab