[R] Subtracting POSIXct data/times
James Rome
jamesrome at gmail.com
Mon Jun 14 22:24:34 CEST 2010
I have two dataframe columns of POXIXct data/times that include seconds.
I got them into this format using for example
zsort$ETA <- as.POSIXct(as.character(zsort$ETA), format="%m/%d/%Y %H:%M:%S")
My problem is that when I subtract the two columns, sometimes the
difference is given in seconds, and sometimes it is given in minutes. I
don't care which it is, but I need to know which one I will get.
DateTime ETA
2010-05-16 02:19:56 2010-05-16 03:46:35
...
Browse[1]> mins = zsort$ETA - zsort$DateTime
Browse[1]> mins
Time differences in hours
[1] 1.444167 2.685000 3.077222 3.210278 3.248056 3.281944 3.281944
3.360278 3.360278 3.582778 4.574444 5.506111 5.857778 6.150278 6.150278
6.243056 6.243889 6.248056 6.248611 6.248611 6.356667
attr(,"tzone")
But sometimes the answer is in seconds.
# make a column with the minutes before landing
>zsort$MinBeforeLand = zsort$ETA - zsort$DateTime
> zsort$MinBeforeLand
Time differences in secs
[1] -50 136 221 878 1192 2263 3296 3959 4968 5846 8709
11537 12198 12442 12642 15952 18273 19952 20538
How do I specify the resultant units?
Thanks,
Jim Rome
More information about the R-help
mailing list