title: Convert yyyymmdd string to Date class in R
body: <p>I would like to convert these dates with format YYYYMMDD to a Date class.</p>
  
  <pre><code>dates &lt;- data.frame(Date = c("20130707", "20130706", "20130705", "20130704"))
  </code></pre>
  
  <p>I tried:</p>
  
  <pre><code>dates &lt;- as.Date(dates, "%Y%m%d")
  </code></pre>
  
  <p>And I get the following error:</p>
  
  <pre><code>Error in as.Date.default(dates, "%Y%m%d") : 
    do not know how to convert 'dates' to class "Date"
  </code></pre>
  
  <p>What would be the correct way to set this format?</p>