0

I have a data frame with 203 column. Some of them string and I want to convert them to factor.

like this :

data$var =  as.factor((data$var))

The problem is, there is 180 string column. Is there a way to do this with a loop or a sapply maybe ? Anything that can help me to not writing this code 180 times.

blabla
  • 402
  • 2
  • 10
  • 17

1 Answers1

-1

I had the same issue to convert into numeric.

The solution for me was to use the following:

data[] <- lapply(data, function(x) as.numeric(as.character(x)))
Single Entity
  • 2,925
  • 3
  • 37
  • 66