Hi there, new guy on the site. :) How do I convert these 22 variables into 5 explanatory variables with levels instead of the current boolean using Rstudio? I’ve tried a few different approaches, but I cannot get it to work properly.
Asked
Active
Viewed 561 times
0
-
Not clear about what you wanted. it is better to show a small example along with expected output instead of images – akrun Nov 01 '18 at 18:02
-
fx, the BuyingPrice columns I would like to combine into a single column so I get a factor BuyingPrice: low (1), medium (2), high (4), and very high (5) to perform a log reg on the data to predict the Evaluation (acceptable or unacceptable) of the car based on 5 explanatory variables. – Christopher Clark Nov 01 '18 at 18:06
-
please see this post on how to post a reproducible question in r https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Mike Nov 01 '18 at 18:36
1 Answers
0
Welcome to SO! have you tried as.factor
?
> as.factor(c(1,0))
[1] 1 0
Levels: 0 1
Say you want to convert columns 2:6 in your df
then:
df[,2:6] <- as.factor(df[,2:6])

gaut
- 5,771
- 1
- 14
- 45