[R] lm error and how to sidestep an error occured in for loop to keep it going without being interrupted

Yong Wang wangyong1 at gmail.com
Thu Sep 27 23:18:18 CEST 2007


Dear Rlist

I am runing a for loop on a large dataset to do exploring
investigation. Code embedded in the loop include the "lm" routine.
Unfortunately, for some specification of dependent variable, the loop
will be interrupted by error as below:

Error in `contrasts<-`(`*tmp*`, value = "contr.treatment") :
        contrasts can be applied only to factors with 2 or more levels

I suspect this might be caused by missing value which, once removed,
will left some factors has value only on one level. It turnss out this
is not true.

Answers for following two questions appreciated.
1. what might be the possible reason behind the error mesage
2. if I simply want to circumvent this error and keep the for loop
going, how should I do that.


Regards
young



More information about the R-help mailing list