title: How to use tryCatch in a for-loop in R
body: <p>I'm trying to estimate a lot of models in a for-loop in R. I first defined a set of possible values for the variable 'Date', and stored these in 'Dates'. Then, for each model, I define a subset of a general dataset, according to these values of 'Dates'.</p>
  
  <p>Eventually, my aim is to store some coefficients of all these models in two matrices: effRain and effWindchill.</p>
  
  <p>The problem is: in some instances, the <code>glmer</code> model cannot be estimated, due to an error. In these cases, I want the loop to skip and continue to the next step in the loop. However, I'm not very experienced in R. I found out I probably need to use <code>tryCatch</code>, but how should I fit this into my code? I've been trying and trying, but I just can't figure it out.</p>
  
  <p>This is my code up till now:</p>
  
  <pre><code>Dates &lt;- c(19710428,19721129,19740529,19770525,19780531,19810526,19820602,19820908,
  19840614,19860319,19860521,19890615,19890906,19900321,19940302,19940503,
  19940609,19980304,19980506,19990303,19990610,20020206,20020515,20030122,
  20030311,20040610,20060307,20061122,20070307,20090604,20100303,20100609,
  20110302,20120912)
  
  effRain &lt;- matrix(nrow=34,ncol=2,0)
  effWindchill &lt;- matrix(nrow=34,ncol=2,0)
  
  for(i in 1:34){
  hulpdata &lt;- hulpdata &lt;- subset(banaan,Date==Dates[i])
  attach(hulpdata)
  SP2 &lt;- SP/100
  model1 &lt;- glmer (cbind(opkomst, nnietgestemd) ~
         (1|gemnr)+ Windchill + Rain + Windspeed + SP2 + lag_popkomst + NB + OL + loginw 
         , family=binomial(link=logit))
  effRain[i] &lt;- coef(summary(model1))[3]
  effWindchill[i] &lt;- coef(summary(model1))[2]
  }
  </code></pre>