Skip to content
Prev 360535 / 398503 Next

Declaring All Variables as Factors in GLM()

Hi guys,

I am running glm(y~., data = history,family=binomial)-essentially, logistic
regression for credit scoring (y = 0 or 1). The dataset 'history' has 14
variables, a few examples:
history <- read.csv("history.csv". header = TRUE)
1> 'income = 100,200,300 (these are numbers in my dataset; however
interpretation is that these are just tags or labels,for every observation,
its income gets assigned one of these tags)
2> 'job' = 'private','government','unemployed','student'

I want to declare all the regressors and y variables *as factors*
programmatically. Would be great if anyone can help me with this (idea is
to loop over variable names and use as.factor - but not sure how to do
this). Thanks

Regards,
Preetam