[R] difftime producing NA values in R 2.12.2

Adrienne Wootten amwootte at ncsu.edu
Tue Oct 25 19:40:48 CEST 2011


R-listers,

I have noticed several posts on issues with difftime producing NA's
but they have been for older versions of R.  Here's the issue
associated with difftime that I am dealing with in R 2.12.2.

> preciptime = strptime("01/10/2007 14:00",format="%m/%d/%Y %H:%M")
> class(preciptime)
[1] "POSIXlt" "POSIXt"
> # Now using difftime, this is what happens
>

> difftime(strptime("03/11/2007 01:00",format="%m/%d/%Y %H:%M"),preciptime,units="hours")
Time difference of 1427 hours

> difftime(strptime("03/11/2007 02:00",format="%m/%d/%Y %H:%M"),preciptime,units="hours")
Time difference of NA hours

> difftime(strptime("03/11/2007 03:00",format="%m/%d/%Y %H:%M"),preciptime,units="hours")
Time difference of 1428 hours

This doesn't make sense to me since both times used in difftime are in
the same format after using strptime, but the differences are coming
out wrong.  It should be 1427, 1428, and 1429, so I'm confused as to
how to fix this.  The idea with the program is to compute the time in
hours since last rainfall, so everything gets thrown off with this
producing NA's.  For reference, Operating system is Windows 7
Enterprise, R is version 2.12.2 (64-bit), any guidance is appreciated.

Thanks in advance!

A
-- 
Adrienne Wootten
Graduate Research Assistant
State Climate Office of North Carolina
Department of Marine, Earth and Atmospheric Sciences
North Carolina State University



More information about the R-help mailing list