[R] transforming character categories
Peter Dalgaard
p.dalgaard at biostat.ku.dk
Sun Jun 28 14:06:18 CEST 2009
Gabor Grothendieck wrote:
> If you only want to convert them to unique numbers then
>
> as.numeric(factor(x))
>
> will do that.
Or, use it directly for indexing, as in c(1000,2500,4173,3700)[factor(x)]
DEPENDING on LEVEL ORDER, mind you! So make sure you know what the order
is or set it yourself using factor(x, levels=...)
--
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