[R] Merging factor levels.

Göran Broström gb at stat.umu.se
Mon Nov 12 16:49:36 CET 2001


This must be a FAQ, but I can't find the answer:
I have a factor 'okk':

> table(okk)
okk
     Other   STORKAGE SKELLEFTEA    FALMARK       BOLE  NEAR_TOWN 
     14064        560        346        526        332         34 

Now I want to put the cases in 'NEAR_TOWN' into the 'Other' category',
so I try:

> okk <- ifelse(okk == "NEAR_TOWN", "Other", okk)
> table(okk)
okk
    1     2     3     4     5 Other 
14064   560   346   526   332    34 
> is.factor(okk)
[1] FALSE

This is not what I intended. I can do what I want the hard way (i.e., by
converting  okk  to character an then back again) but there 
must be something simpler?

Thanks,

Göran
-- 
 Göran Broström                      tel: +46 90 786 5223
 professor                           fax: +46 90 786 6614
 Department of Statistics            http://www.stat.umu.se/egna/gb/
 Umeå University
 SE-90187 Umeå, Sweden             e-mail: gb at stat.umu.se

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list