Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

finvert

Inverts the values of a factor


Description

Useful function to invert the values from a categorical variable, for instance a Likert response scale.

Usage

finvert(x, levels = FALSE)

Arguments

x

A categorical variable (a factor)

levels

Logical, invert the levels as well

Value

A factor of the same length as the original one.

Author(s)

Adrian Dusa

Examples

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)

admisc

Adrian Dusa's Miscellaneous

v0.12
GPL (>= 3)
Authors
Adrian Dusa [aut, cre, cph] (<https://orcid.org/0000-0002-3525-9253>)
Initial release
2021-03-16

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.