[R] factor
Peter Dalgaard
p.dalgaard at biostat.ku.dk
Wed Feb 4 08:12:44 CET 2009
kayj wrote:
> I am looking into change the numeric order in the level of the factor
>
>> x<-c("A","B","C")
>> fx<-factor(x)
>> fx
> [1] A B C
> Levels: A B C
>> factor(x)
> [1] A B C
> Levels: A B C
>> as.numeric(fx)
> [1] 1 2 3
>
> I want to change the order of the numeric into 3 corresponds to “A” level, 2
> corresponds to “B” level and 1 corresponds to “C” level
>
> So when I type in
>
> As.numeric(fx) I would like to get
>
> 3 2 1
>
> Your help is greatly appreciated
>
fx <- factor(x, levels=c("C","B","A"))
--
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