Quantcast
Channel: Coerce multiple columns to factors at once - Stack Overflow
Viewing all articles
Browse latest Browse all 13

Coerce multiple columns to factors at once

$
0
0

I have a sample data frame like below:

data <- data.frame(matrix(sample(1:40), 4, 10, dimnames = list(1:4, LETTERS[1:10])))

I want to know how can I select multiple columns and convert them together to factors. I usually do it in the way like data$A = as.factor(data$A). But when the data frame is very large and contains lots of columns, this way will be very time consuming. Does anyone know of a better way to do it?


Viewing all articles
Browse latest Browse all 13

Latest Images

Trending Articles





Latest Images