# factor with levels a, b, c, d, e, f (in that order)
x <- factor(c(1, 4, 2, 2, 3, 3, 5, 5, 6, 6), labels = letters[1:6])
levels(x)
# move level e to position 1, c to position 2, b to 3, a to 4, d to 5, f to 6
permuteLevels(x, perm = c(5, 3, 2, 1, 4, 6))
# using invert = TRUE: move level a to position 5, b to 3, c to 2, etc.
permuteLevels(x, perm = c(5, 3, 2, 1, 4, 6), invert = TRUE)
Run the code above in your browser using DataLab