[R] ifelse with a factor variable

Goran Brostrom gb at tal.stat.umu.se
Tue Oct 28 21:36:21 CET 2003


'ifelse' changes factors to character vectors (R-1.7.1, Linux):

> table(bal$soc.40)

          tax         noble semi-landless      landless       unknown 
         4035          5449         13342          9348             0 


> blah <- ifelse(is.na(bal$soc.40), "unknown", bal$soc.40)
> table(blah)
blah
      1       2       3       4 unknown 
   4035    5449   13342    9348    7970 

How do I get what I want (I mean: simply)? Upgrade to 1.8.0?

Göran




More information about the R-help mailing list