[R] strptime "March 14 2010" and NA?

Manuel Gimond mgimond at colby.edu
Tue Feb 8 18:40:21 CET 2011


On 2/8/2011 11:47 AM, David Winsemius wrote:

>
>  On Feb 8, 2011, at 10:31 AM, Manuel Gimond wrote:
>
>>  Converting date strings that range between Mar-14-2010 2:00 and
>>  Mar-14-2010 2:59 (inclusive) to date objects (POSIX) returns a NA
>>  entity:
>>
>>>  strptime("3/14/2010 2:00",format="%m/%d/%Y %H:%M")
>>  [1] "2010-03-14 02:00:00"
>>
>>  This looks fine, however other functions such as plot see a NA object
>>  instead:
>>
>>>  is.na(strptime("3/14/2010 2:00",format="%m/%d/%Y %H:%M"))
>>  [1] TRUE
>>
>>  I've processed an entire range of dates for 2010 and have only come
>>  across this problem for the aforementioned date ranges. For instance,
>>  the following dates work fine:
>>
>>>  is.na(strptime("3/14/2010 3:00",format="%m/%d/%Y %H:%M"))
>>  [1] FALSE
>>
>>>  is.na(strptime("10/14/2010 23:00",format="%m/%d/%Y %H:%M"))
>>  [1] FALSE
>>
>>  which is what I would expect for ALL dates.
>>
>>  Could this be a bug with POSIX or strptime?
>
>  More likely it has to do with "daylight savings time".
>
>
Thanks David, DST was indeed the problem. The data I'm working with is
in local standard time. Adding the tz="EST" fixed the problem, e.g.:

>  is.na(strptime("3/14/2010 2:00",format="%m/%d/%Y %H:%M",tz="EST"))
[1] FALSE



More information about the R-help mailing list