Skip to content
Prev 132080 / 398506 Next

Conflating categories

On 12/14/2007 7:39 AM, Peter Paul wrote:
This is a little tricky, because R has probably converted those columns 
into factors.  Let's assume that column 2 is named Type and the dataset 
is named dat.

Then you replace it as

dat$Type[dat$Type == "Advice"] <- "GeneralInfo"

You'd think the following would work:

dat$Type <- ifelse(dat$Type == "Advice", "GeneralInfo", dat$Type)

but it doesn't, because ifelse() loses the factor levels.  Factors are 
one of the most error-prone features of the S language.

Duncan Murdoch