I am trying to bulk convert numeric and character class variables to factor in R. I feel that this should be simple, but I am running into an issue actually getting it to factor
What I have done is here:
>sapply(df, class)
a b c
"numeric" "numeric" "numeric"
>col.names <- c("a", "b", "c")
>df[,col.names] <- sapply(df[,col.names], as.factor)
and what I get back it this:
>sapply(df, class)
a b c
"character" "character" "character"
And I am trying to figure out why it wouldn't convert from numeric to factor, and instead is going to character.
Typically the problem is going from factor to numeric, so I haven't been able to find anything about this type of issue.
lapply. - Rui Barradascharacter. - Rui Barradas