title: do not know how to convert 'outcome[, col]' to class “Date”
body: <p>I wrote the following script in R software in order to converting date format in a prospective cohort data. But, I get an odd error. Could everyone help me? Any idea?</p>
  
  <p>Code:</p>
  
  <pre><code>for(col in colnames(outcome)){
    if(startsWith(col, "eventdate_")){
      outcome[, col] &lt;- as.Date(outcome[, col],"%Y-%m-%d")
    }
  }
  </code></pre>
  
  <p>Error: 
  Error in as.Date.default(outcome[, col], format = "%Y-%m-%d") : 
    do not know how to convert 'outcome[, col]' to class “Date”</p>