title: Efficiently formatting date and time in large data sets in R - dplyr performance
body: <p>This question is on code performance. I have a data frame with two columns:</p>
  
  <ul>
  <li><code>DATE</code> is represented as numeric in <code>MMDDYYYY</code> format</li>
  <li><code>EPOCH</code> is a representation of time in 5 minute increments from midnight. <code>EPOCH</code> count starts at 0 - so 00:00 to 00:05 would be 0, 00:05 to 00:10 would be 1 and so on. </li>
  </ul>
  
  <p>I have about 15 million rows of data in my data frame. As a part of processing this data I am converting the two columns to R's <code>Date</code> and <code>POSIXct</code> format. I am using <code>dplyr</code> - however, the code I have is taking way too long (about 30 minutes). Below I am generating a toy data set and provided the code I am using:</p>
  
  <pre><code>library(dplyr)
  DATA &lt;- data.frame(DATE = rep(10082013,15000000), EPOCH = rep(6,15000000))
  </code></pre>
  
  <p>Here is a sample view of the data </p>
  
  <pre><code>DATA %&gt;% 
    head()
  
       DATE EPOCH
  1 10082013     6
  2 10082013     6
  3 10082013     6
  4 10082013     6
  5 10082013     6
  6 10082013     6
  </code></pre>
  
  <p>This is the part where I transform the data into the format I want it in:</p>
  
  <pre><code>DATA %&gt;%
    mutate(DATE_FORMATTED = as.Date(as.character(DATE), "%m%d%Y")) %&gt;%
    mutate(DOW = weekdays(DATE_FORMATTED)) %&gt;%
    mutate(TIME_FORMATTED = strftime(as.POSIXct(((EPOCH+1)*5*60), origin=as.character(DATE_FORMATTED), tz="UTC"), format="%R", tz="UTC")) %&gt;%
    head()
  </code></pre>
  
  <p>I feel the overhead is due to all the coercions in the <code>TIME_FORMATTED</code> formula. Is there a way to achieve the end result faster? Maybe a different function that is <code>dplyr</code> optimized?</p>