[R] Remove columns from data-frame

Maciej Bliziński m.blizinski at wsisiz.edu.pl
Mon Mar 21 11:12:57 CET 2005


Hello,

I'm new to the list, hello everybody! :-)


I have a question. I looked carefully through the documentation and
googled, and found no answer, so I'm posting it here.

Let's say I have a data frame with lots of columns (about 300), which
are factors.  Many columns-factors have only one level, for example all
are "Yes" or all are "No". 

If I try to do a regression with that, I get an error message, that
contrasts can be used only when number of factors is at least 2.

> glm(mortality ~ ., family = binomial, data = ecdb_PROC88)
Error in "contrasts<-"(`*tmp*`, value = "contr.treatment") :
        contrasts can be applied only to factors with 2 or more levels


Of course, I could not include them in the model formula, but I don't
feel like typing 150 descriptive variables.

I would like to remove the one-level columns autimatically from the data
frame. Is it possible?

Regards,
Maciej




More information about the R-help mailing list