[R] / Operator not meaningful for factors
Petr PIKAL
petr.pikal at precheza.cz
Tue May 4 11:09:54 CEST 2010
Hi
Yes, it is also possible. I usually use
as.numeric(as.character(some.factor.which can.be.transformed.to.numeric))
Regards
Petr
"Katya Mauff" <Katya.Mauff at uct.ac.za> napsal dne 04.05.2010 10:42:20:
> apologies-try something like this:
> > x<-rnorm(5)
> > x
> [1] 0.9128818 1.5615704 -1.2319878 -1.8689400 -1.2931785
> > x.f<-factor(x)
> > x.f
> [1] 0.912881849717846 1.56157044807315 -1.2319877852522
-1.8689399737313
> -1.29317849983031
> Levels: -1.8689399737313 -1.29317849983031 -1.2319877852522
0.912881849717846
> 1.56157044807315
> > y=as.numeric(levels(x.f))[x.f]
> > y
> [1] 0.9128818 1.5615704 -1.2319878 -1.8689400 -1.2931785
>
>
>
>
>
> >>> Petr PIKAL <petr.pikal at precheza.cz> 2010/05/04 10:12 AM >>>
>
> > x<-rnorm(5)
> > x
> [1] -1.1550254 -0.4578429 -0.6089007 -1.7378599 0.1297853
> > x.f<-factor(x)
> > x.f
> [1] -1.15502538070463 -0.457842907389024 -0.608900689299125
> -1.73785992416606
> [5] 0.129785271221269
> 5 Levels: -1.73785992416606 -1.15502538070463 ... 0.129785271221269
> > as.numeric(x.f)
> [1] 2 4 3 1 5
>
>
______________________________________________________________________________________________
> UNIVERSITY OF CAPE TOWN
> This e-mail is subject to the UCT ICT policies and e-mail disclaimer
published
> on our website at http://www.uct.ac.za/about/policies/emaildisclaimer/
or
> obtainable from +27 21 650 4500. This e-mail is intended only for the
person
> (s) to whom it is addressed. If the e-mail has reached you in error,
please
> notify the author. If you are not the intended recipient of the e-mail
you may
> not use, disclose, copy, redirect or print the content. If this e-mail
is not
> related to the business of UCT it is sent by the sender in the sender's
> individual capacity.
>
More information about the R-help
mailing list