[R] Replace number with month

Peter Dalgaard P.Dalgaard at biostat.ku.dk
Thu Jun 21 10:15:30 CEST 2007


Don MacQueen wrote:
> You can get the names using
>
>    month.name[MM]
>
>
> And it may be necessary to use
>
>      factor(month.name[MM], levels=month.name[1:12])
>
> to get them to show up in the correct order in the barchart.
>   

You're crossing the creek to fetch water there, and getting yourself
soaked in the process... (by an unnecessary conversion to character
which is subject to alphabetical sorting)

I think the canonical way is

factor(MM, levels=1:12, labels=month.name)

(and the levels=1:12 may not even be necessary when all 12 months are
present)

-- 
   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 at biostat.ku.dk)                  FAX: (+45) 35327907



More information about the R-help mailing list