Hey there!
I have a data frame with several categorical variables. I want some of those variables to be changed as factors in R, the have the same components since it was a survey (yes/no answers)/. I want to create a function to just insert all these variables and automatically be changed to factor insted of copying and pasting on and on.
categorical <- function(put){
sueldo$put <- factor(sueldo$put, levels = c(1,2),
labels= c('sí','No'))
}
However, when I insert my variable I get the error:
Error: Assigned data factor(sueldo$put, levels = c(1, 2), labels = c("sí", "No")) must be compatible with existing data. x Existing data has 28394 rows. x Assigned data has 0 rows. i Only vectors of size 1 are recycled.
This is for an institutional project thanks for your help guys.