[R] Remove columns from data-frame

From: Maciej Bliziński <m.blizinski_at_wsisiz.edu.pl>
Date: Mon 21 Mar 2005 - 21:12:57 EST


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?


R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Mon Mar 21 21:24:32 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:30:51 EST