Skip to content
Prev 167330 / 398502 Next

converting a factor in numeric values with direct control of the numeric values

ifelse is your friend:

 > z <- c("male", "male", "female")
 >  z <- as.factor(z)
 >
 >  z <- ifelse(z == "male", 3, 5)

 > z
[1] 3 3 5
 > class(z)
[1] "numeric"
 >

--  
David Winsemius
On Jan 17, 2009, at 11:40 AM, J?rg Gro? wrote: