Reverse the levels of a factor.
reverse.levels(x)
a factor or a data.frame of factors whose levels will be reverse coded.
mylevels <- c('Strongly Disagree', 'Disagree', 'Neither', 'Agree', 'Strongly Agree')
test <- factor(sample(mylevels[1:5], 10, replace=TRUE))
cbind(test, as.integer(test), as.integer(reverse.levels(test)))
#> test
#> [1,] 2 2 4
#> [2,] 3 3 3
#> [3,] 4 4 2
#> [4,] 1 1 5
#> [5,] 4 4 2
#> [6,] 2 2 4
#> [7,] 1 1 5
#> [8,] 4 4 2
#> [9,] 3 3 3
#> [10,] 5 5 1