Spencer Jones
2006-Oct-05 17:14 UTC
[R] convert day of week from number to character and include in lm
All, I am trying to include a day of week variable (1-7) in in a regression model. I would like to have the day of week treated as a categorical variable rather than a number the code looks like lm( dep ~ WKDY) I know this is a basic question, but help would be appreciated thanks spencer [[alternative HTML version deleted]]
Ferdinand Alimadhi
2006-Oct-06 00:22 UTC
[R] convert day of week from number to character and include in lm
lm(dep ~ as.factor(WKDY) but if you want WKDYs as character you can make the appropriate changes in your dataset > days<-c("mon","tue","wed","thu","fri","sat","sun") > for(i in 1:7) + D$WKDY[D$WKDY==i]<-days[[i]] suppossing that D is your dataframe HTH Spencer Jones wrote:>All, > >I am trying to include a day of week variable (1-7) in in a regression >model. I would like to have the day of week treated as a categorical >variable rather than a number > >the code looks like > >lm( dep ~ WKDY) > >I know this is a basic question, but help would be appreciated > >thanks > >spencer > > [[alternative HTML version deleted]] > >______________________________________________ >R-help at stat.math.ethz.ch mailing list >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code. > > >-- Ferdinand Alimadhi Programmer / Analyst Harvard University The Institute for Quantitative Social Science (617) 496-0187 falimadhi at iq.harvard.edu www.iq.harvard.edu