title: What is the R equivalent for Excel IFERROR?
body: <p>I am trying to put IFERROR condition in R like Excel IFERROR Function. I am building a random forest model. To fine tune, i use tuneRF function. It helps to give optimal mtry parameter.</p>
  
  <pre><code>#Selecting Optimal MTRY parameter
  mtry &lt;- tuneRF(dat3[, -36], dat3[,36], ntreeTry=1000, stepFactor=1.5,improve=0.01, trace=TRUE, plot=TRUE)
  best.m &lt;- mtry[mtry[, 2] == min(mtry[, 2]), 1]
  </code></pre>
  
  <p><strong>SOMETIMES, the above function returns error if OOB error would not improve in different iterations.</strong> </p>
  
  <p><strong>Error in if (Improve > improve) { : missing value where TRUE/FALSE 
  needed.</strong></p>
  
  <p>Next Step : If the above function works fine, i use the value of best.m in the code below.</p>
  
  <p><strong>No ERROR in tuneRF function - Run the code below.</strong></p>
  
  <pre><code>rf &lt;-randomForest(classe~.,data=dat3, mtry=best.m, importance=TRUE,ntree=1000)
  </code></pre>
  
  <p><strong>ERROR in tuneRF function - Run the code below.</strong></p>
  
  <pre><code>#Train Random Forest
  rf &lt;-randomForest(classe~.,data=dat3, importance=TRUE,ntree=1000)
  </code></pre>
  
  <p>Thanks in anticipation! Any help would be highly appreciated.</p>