title: using tryCatch() in R to assign error values in loop
body: <p>I am struggling with the instructions for tryCatch() in R.  I'm trying to capture the closing price for a ticker.  </p>
  
  <p>Case 2 = good case = TickersJuly2 = unique price to ticker relationship</p>
  
  <p>Case 1 = bad case = TickersJuly1 = FABU close price is the repeat of CETX</p>
  
  <p>Case 1 desired output is a 0 for FABU.</p>
  
  <pre><code>library(TTR)
  close.price1=NULL
  TickersJuly1 &lt;- c('DIT','CETX','FABU')
  TickersJuly2&lt;- c('AAPL','A','AA')
  
  for(i in TickersJuly1){
             tryCatch(close &lt;- getYahooData(i,20150727,20150727,'daily',"price"),
                 error = function(e) close$Close &lt;- 0,
                 warning = function(w) close$Close &lt;- 0,
                 finally = function(f) close$Close &lt;- 0)
        close.price &lt;- c(as.character(close$Close),i)
        close.price1 &lt;- rbind(close.price1,close.price)
  }
  </code></pre>