Re: [R] convert day of week from number to character and include in lm

From: Peter Dalgaard <p.dalgaard_at_biostat.ku.dk>
Date: Fri 06 Oct 2006 - 07:35:34 GMT

Ferdinand Alimadhi <falimadhi@iq.harvard.edu> writes:

> 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

Come on...

  factor(WKDY, labels=days)

If you insist on a character result, take as.character(), or just

  days[WKDY]  

> 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@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@iq.harvard.edu
> www.iq.harvard.edu
>
> ______________________________________________
> R-help@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.
>

-- 
   O__  ---- Peter Dalgaard             Ă˜ster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)                  FAX: (+45) 35327907

______________________________________________
R-help@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.
Received on Fri Oct 06 17:43:07 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 06 Oct 2006 - 08:30:08 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.