title: R how to get index of the values in a for loop
body: <p>I am doing some processing and this is my code</p>
  
  <pre><code>wrongDateValues &lt;- function(date){
      wrongIndexes &lt;- c()
      wrongValues &lt;- c()
      for(value in date){
        formattedDate &lt;- strptime(value, "%Y%m%d")
        if(is.na(formattedDate)){
          wrongValues &lt;- c(wrongValues, value)
          wrongIndexes &lt;- c(wrongIndexes, value)
        }
      }
      wrongResults &lt;- matrix(c(wrongValues, wrongIndexes), byrow = FALSE, ncol = 2)
      colnames(wrongResults) &lt;- c("WrongValues", "WrongIndexes")
      return (wrongResults)
  }
  </code></pre>
  
  <p>as you see, now in the <code>wrongIndexes</code> i am saving the values, because ** i don't know how to save the index**</p>
  
  <p>could you help?</p>