[R] how to model a numeric factor as a non-ordinal factor
Peter Dalgaard
p.dalgaard at biostat.ku.dk
Wed Oct 28 18:34:03 CET 2009
Mark Kimpel wrote:
> I am analyzing an experiment in which time is a factor, represented by
> numbers indicating time since last treatment, but in this particular case
> there is no reason to think that time has a numeric meaning in the sense
> that 24 would be greater than 6. We have no idea which genes will be
> increasing or decreasing at different times.
>
> So I have the following model (to be applied over many genes):
>
> mod <- lm(gene.expression ~ Treatment + Time)
>
> If I wanted to just hack my way around this I could just paste a character
> to all of the times, but I'm curious as to the right way to do this.
>
> What would be the correct syntax or transformation? Would Time <-
> factor(as.character(Time)) do it? I want to make sure that it does not get
> coerced back to numeric.
Just factor(Time) should do it. (If you do as.character first, you get
the levels sorted alphabetically, which you'd probably rather not).
--
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