Use of as.factor in R

r

#1

Hello,

While going to some kaggle problem tutorials on the net, I found heavy usage of the function as.factor().
I wanted to know about the exact purpose of the function and how to know when we have to use it and when not and for what kind of variables.

Thanks.


#2

as.factor is used when you want to convert the data type of a variable to a factor/categorical variable. Typically when you want to convert a numeric/integer/character variable into a categorical variable we use as.factor.