Reputation: 1
I have a data frame with 100 columns and I want to convert them all into factor. Let's assume the data frame,
a <- as.integer(c(1,2,1,2,1,1))
b <- as.integer(c(1,2,3,3,3,1))
df <- data.frame(a,b)
I am trying this,
library(dplyr)
colwise(df, as.factor(df))
which give me an error like this,
> colwise(df, as.factor(df))
Error in sort.list(y) : 'x' must be atomic for 'sort.list'
Have you called 'sort' on a list?
Any suggestion how to do this correct? Thanks in advance.
Upvotes: 0
Views: 87
Reputation: 887118
With dplyr
, we use factor
within mutate_all
for converting all columns to factor
library(dplyr)
df %>%
mutate_all(factor)
Upvotes: 2