Collapsing categorical data easily for regression in R I have read an article from Christopher Manning, and saw an interesting code for collapsing categorical variable in an logistic regression model:
glm(ced.del ~ cat + follows + I(class == 1), family=binomial("logit"))

Does the I(class == 1) means that the class variable has been recoded into either it is 1 or it is not 1?
After that, I am thinking of modifying it a bit:
glm(ced.del ~ cat + follows + I(class %in% C(1,2)), family=binomial("logit"))

I am planning to merge the variable class from c(1,2,3,4) into two groups, one group contains c(1,2), another group contains c(3,4), can the code above give me the result I want?
 A: This shows what the first is doing:
> class <- sample(1:5, 10, replace = TRUE)
> class == 1
 [1]  TRUE FALSE FALSE FALSE  TRUE  TRUE  TRUE FALSE  TRUE  TRUE
> as.numeric(class == 1)
 [1] 1 0 0 0 1 1 1 0 1 1
> ## or better,
> factor(as.numeric(class == 1))
 [1] 1 0 0 0 1 1 1 0 1 1
Levels: 0 1

class == 1 is creating an indicator variable as you surmise. The I(....) bit is due to us having to insulate certain operations from R's formula parsing code.
Similarly, class %in% c(1,2) is doing the same thing but matching on 1 or 2:
> class %in% c(1,2)
 [1]  TRUE FALSE FALSE  TRUE  TRUE  TRUE  TRUE FALSE  TRUE  TRUE
> as.numeric(class %in% c(1,2))
 [1] 1 0 0 1 1 1 1 0 1 1
> ## etc

and it works within the modelling calls:
> set.seed(1)
> dat <- data.frame(Y = rnorm(100), X1 = rnorm(100), 
+                   class = sample(1:5, 100, replace = TRUE))
> mod <- lm(Y ~ X1 + I(class %in% c(1,4)), data = dat)
> coef(mod)
              (Intercept)                        X1 I(class %in% c(1, 4))TRUE 
                  0.138287085              -0.003827624              -0.072059592 

but I think it is neater if you create a new variable for the class compression you want and use that directly in your model:
> dat <- within(dat, class2 <- factor(class %in% c(1, 4),
+                                     levels = c(FALSE,TRUE)))
> mod2 <- lm(Y ~ X1 + class2, data = dat)
> coef(mod2)
 (Intercept)           X1   class2TRUE 
 0.138287085 -0.003827624 -0.072059592

