title: R: Date Operation Results in Empty Dates
body: <p>I am using the R programming language. I am trying to take the difference between two date columns. Both  dates are in the following format : 2010-01-01 12:01</p>
  <p>When I bring my file into R, the dates are in &quot;Factor&quot; format. Here is my attempt to recreate the file in R:</p>
  <pre><code>#how my file looks like when I import it into R
  
  date_1 = c(&quot;2010-01-01 13:01 &quot;, &quot;2010-01-01 14:01&quot; )
  date_2 = c(&quot;2010-01-01 15:01 &quot;, &quot;2010-01-01 16:01&quot; )
  
  file = data.frame(date_1, date_2)
  file$date_1 = as.factor(file$date_1)
  file$date_2 = as.factor(file$date_2)
  </code></pre>
  <p>Now, I am trying to create a new column which takes the difference between these dates (in minutes)</p>
  <p>I first tried to convert both date variables into the appropriate &quot;Date&quot; formats:</p>
  <pre><code>#convert to date formats:
      
    file$date_a = as.POSIXlt(file$date_1,format=&quot;%Y-%m-%dT%H:%M&quot;)
    file$date_b = as.POSIXlt(file$date_2,format=&quot;%Y-%m-%dT%H:%M&quot;)
  </code></pre>
  <p>Then, I tried to take the difference :</p>
  <pre><code>file$diff = difftime(file$date_a, file$date_b, units=&quot;mins&quot;)
  </code></pre>
  <p>But this results in &quot;NA's&quot;:</p>
  <pre><code>&gt; file
  
               date_1            date_2 date_a date_b    diff
  1 2010-01-01 13:01  2010-01-01 13:01    &lt;NA&gt;   &lt;NA&gt; NA mins
  2  2010-01-01 13:01  2010-01-01 13:01   &lt;NA&gt;   &lt;NA&gt; NA mins
  </code></pre>
  <p>Can someone please show me what I am doing wrong?</p>
  <p>Thanks</p>
  <p>Reference: <a href="https://stackoverflow.com/questions/33068340/how-to-get-difference-in-minutes-between-two-date-strings">How to get difference (in minutes) between two date strings?</a></p>