That fixed it. Dumb me. I had assumed that the subtraction of the raw POSIXcts would always give the same results.
Thanks, Jim On 6/14/10 5:22 PM, Don MacQueen wrote: > See the help page for the difftime() function, which will tell you how > to specify the units of the differences. > (when you don't specify, it chooses the units according to some rules) > > -Don > > At 4:24 PM -0400 6/14/10, James Rome wrote: >> 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 >> >> ______________________________________________ >> R-help@r-project.org mailing list >> https://*stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://*www.*R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. > > ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.