title: Why is as.Date slow on a character vector?
body: <p>I started using data.table package in R to boost performance of my code. I am using the following code:</p>
  
  <pre><code>sp500 &lt;- read.csv('../rawdata/GMTSP.csv')
  days &lt;- c("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday")
  
  # Using data.table to get the things much much faster
  sp500 &lt;- data.table(sp500, key="Date")
  sp500 &lt;- sp500[,Date:=as.Date(Date, "%m/%d/%Y")]
  sp500 &lt;- sp500[,Weekday:=factor(weekdays(sp500[,Date]), levels=days, ordered=T)]
  sp500 &lt;- sp500[,Year:=(as.POSIXlt(Date)$year+1900)]
  sp500 &lt;- sp500[,Month:=(as.POSIXlt(Date)$mon+1)]
  </code></pre>
  
  <p>I noticed that the conversion done by as.Date function is very slow, when compared to other functions that create weekdays, etc. Why is that? Is there a better/faster solution, how to convert into date-format? (If you would ask whether I really need the date format, probably yes, because then use ggplot2 to make plots, which work like a charm with this type of data.)</p>
  
  <p>To be more precise</p>
  
  <pre><code>&gt; system.time(sp500 &lt;- sp500[,Date:=as.Date(Date, "%m/%d/%Y")])
     user  system elapsed 
   92.603   0.289  93.014 
  &gt; system.time(sp500 &lt;- sp500[,Weekday:=factor(weekdays(sp500[,Date]), levels=days, ordered=T)])
     user  system elapsed 
    1.938   0.062   2.001 
  &gt; system.time(sp500 &lt;- sp500[,Year:=(as.POSIXlt(Date)$year+1900)])
     user  system elapsed 
    0.304   0.001   0.305 
  </code></pre>
  
  <p>On MacAir i5 with slightly less then 3000000 observations.</p>