[R] converting a factor in numeric values with direct control of the numeric values

Jörg Groß joerg at licht-malerei.de
Sat Jan 17 17:40:18 CET 2009


Hi,

I know how to convert a factor-variable into a numeric variable via  
as.numeric().

But how can I control the values that are assigned?


For example, I have this factor-variable:


z <- c("male", "male", "female")
z <- as.factor(z)


And I want to convert male in 3 and female into the numeric value 5  
(just for the example)

so that I get:

[1] 3 3 5


Thanks for any help!




More information about the R-help mailing list