Inverts the values of a factor
Useful function to invert the values from a categorical variable, for instance a Likert response scale.
finvert(x, levels = FALSE)
x |
A categorical variable (a factor) |
levels |
Logical, invert the levels as well |
A factor of the same length as the original one.
Adrian Dusa
words <- c("ini", "mini", "miny", "moe") variable <- factor(words, levels = words) # inverts the value, preserving the levels finvert(variable) # inverts both values and levels finvert(variable, levels = TRUE)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.