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

Moshe Olshansky m_olshansky at yahoo.com
Fri Sep 28 08:12:06 CEST 2007


For an answer to your question 2. look at help(try)
and help(tryCatch).

--- Yong Wang <wangyong1 at gmail.com> wrote:

> 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
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained,
> reproducible code.
>



More information about the R-help mailing list