How to create labels in a binary vector without it becoming categorical?


I have a binary variable in a dataframe , I want to assign the label "no" to the value 0 and "yes" to the value 1 without the vector becoming categorical (if that happens, I can't use the svymean() function).

Does anyone know if this is possible?


That's not possible.

What you can do is let the R transform into a factor, and when using svymean do like this:

x <- c("sim", "sim", "não", "não")
svymean(x = as.numeric(x == "sim"), design = ?)

Note that using as.numeric(x == "sim") drops a vector of zeros and ones:

[1] 1 1 0 0
Scroll to Top