Creating a new column which gives the difference in time between two other columns in condition to another column in R
<p>My data is like this. df is the name of the dataframe</p>

<pre><code>Status          ArrivalDate                   ClosedDate       
Closed          2015-12-01 04:40:24         2015-12-08  10:12:08
In Progress     2015-12-03 06:40:00
Pending         2015-12-12 08:40:54
Cancelled       2015-12-06 04:40:24         2015-12-18  11:33:50
</code></pre>

<p>Status has 4 factors:Closed,Cancelled,In-Progress,Pending
In-Progress and Pending don't have ClosedDates</p>

<p>I want to create another column which gives the time difference between ArrivalDate and ClosedDate only if Status is Closed or Cancelled.</p>

<p>This is the code i'm using now:</p>

<pre><code>df$Life[df$Status=="Closed"|df$Status=="Cancelled"]&lt;-difftime(df$Arrival.Date,df$Closed.Date)
</code></pre>

<p>And this is the error message I'm getting</p>

<blockquote>
  <p>Error in as.POSIXlt.character(x, tz, ...) : 
    character string is not in a standard unambiguous format</p>
</blockquote>

<p>PS: <code>difftime()</code> works properly when I tried with just two dates. When extended to the whole column it shows the error.</p>