[R] Odp: strange error msg from lapply and lm()

Petr PIKAL petr.pikal at precheza.cz
Tue May 4 10:09:19 CEST 2010


r-help-bounces at r-project.org napsal dne 03.05.2010 16:24:11:

> I am conducting a very simple t test for two genes using lapply (i try 
> avoid loop since i will have thousands of genes later on). however, I 
> strange error msg like the followings. It looks that R is complaining my
> factor has only one level, which is not the case (I check many times).

In each split?

sum(rowSums(sapply(split(all$treatment,all$CHIPEXP_NAME), function(x) 

shall tell you if there are some parts of your split which has only 1 or 
less non empty levels.

What is the result in your case? Shall be zero.


> > result<- lapply(split(all,all$CHIPEXP_NAME),function(x)
> > lm(logvalue~treatment,x))
> Error in `contrasts<-`(`*tmp*`, value = "contr.treatment") : 
>   contrasts can be applied only to factors with 2 or more levels
> can anyone help me to dissect this problem?
> thanks in advance.
> -- 
> View this message in context: 
> from-lapply-and-lm-tp2124042p2124042.html
> Sent from the R help mailing list archive at Nabble.com.
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list