Recode categorical variable

In R there is no label attribute for factors (categorical variables) labels get converted to levels (categories), so you may want to just use your labels as levels like this.

library(car)

x <- as.factor(c(1, 2, 3, 4, 5, 6, 7))
recode(x, "1:2='no access';3:5='with access';else=NA")
#> [1] no access   no access   with access with access with access <NA>       
#> [7] <NA>       
#> Levels: no access with access

Created on 2019-03-03 by the reprex package (v0.2.1)

1 Like