[R] strange date problem - May 3, 1992 is NA

Alexander Shenkin ashenkin at ufl.edu
Wed Jun 22 22:32:49 CEST 2011


Wow.  Setting my timezone to UTC -5 Bogota (where there is no daylight
savings time), I get the error:

> is.na(strptime("5/3/1992", format="%m/%d/%Y"))
[1] TRUE

But setting it to UTC -5 East Coast Time (whether or not I tell windows
to adjust for DST) I get:

> is.na(strptime("5/3/1992", format="%m/%d/%Y"))
[1] FALSE

Can others test this on their systems?  How strange.  I wonder how much
tropical forest carbon this will account for.  :-)

Thanks,
Allie

On 6/22/2011 3:23 PM, William Dunlap wrote:
> The isdst value -1 doesn't seem right.  Shouldn't it
> be either 0 (not daylight savings time) or 1 (yes dst)?
> I've only seen isdst==-1 when all the other entries
> were NA (that happens when the string doesn't match
> the format).
> 
> In the parts of the US where daylight savings time is
> used the switchover took place near the beginning of
> April in 1992, so you should have isdst=1 by May 3.
> Perhaps you have an odd timezone file on your machine.
> 
> Bill Dunlap
> Spotfire, TIBCO Software
> wdunlap tibco.com  
> 
>> -----Original Message-----
>> From: Alexander Shenkin [mailto:ashenkin at ufl.edu] 
>> Sent: Wednesday, June 22, 2011 1:07 PM
>> To: William Dunlap
>> Subject: Re: [R] strange date problem - May 3, 1992 is NA
>>
>> Hi Bill,
>>
>> Thanks for your reply.  The results look almost identical to my eyes,
>> except for the mysterious "TRUE"...
>>
>>> methods("is.na")
>> [1] is.na.data.frame      is.na.numeric_version is.na.POSIXlt
>>> trace(methods("is.na"), quote(cat(" is.na: class(x)=", 
>> class(x), "\n")))
>> Tracing function "is.na.data.frame" in package "base"
>> Tracing function "is.na.numeric_version" in package "base"
>> Tracing function "is.na.POSIXlt" in package "base"
>> [1] "is.na.data.frame"      "is.na.numeric_version" "is.na.POSIXlt"
>>> z <- strptime("5/3/1992", format="%m/%d/%Y")
>>> is.na(z)
>> Tracing is.na.POSIXlt(z) on entry
>>  is.na: class(x)= POSIXlt POSIXt
>> [1] TRUE
>>> str(unclass(z))
>> List of 9
>>  $ sec  : num 0
>>  $ min  : int 0
>>  $ hour : int 0
>>  $ mday : int 3
>>  $ mon  : int 4
>>  $ year : int 92
>>  $ wday : int 0
>>  $ yday : int 123
>>  $ isdst: int -1
>>
>>
>>> sessionInfo()
>> R version 2.12.1 (2010-12-16)
>> Platform: i386-pc-mingw32/i386 (32-bit)
>>
>> locale:
>> [1] LC_COLLATE=English_United States.1252
>> [2] LC_CTYPE=English_United States.1252
>> [3] LC_MONETARY=English_United States.1252
>> [4] LC_NUMERIC=C
>> [5] LC_TIME=English_United States.1252
>>
>> attached base packages:
>> [1] stats     graphics  grDevices utils     datasets  methods   base
>>
>> loaded via a namespace (and not attached):
>> [1] tools_2.12.1
>>
>> thanks,
>> allie
>>
>> On 6/22/2011 1:50 PM, William Dunlap wrote:
>>> What do you get for the following commands, which
>>> show which is.na method is getting called and
>>> the internal structure of the dataset made
>>> by strptime?
>>>
>>>> methods("is.na")
>>> [1] is.na.data.frame      is.na.numeric_version is.na.POSIXlt
>>>> trace(methods("is.na"), quote(cat(" is.na: class(x)=", class(x),
>>> "\n")))
>>> Tracing function "is.na.data.frame" in package "base"
>>> Tracing function "is.na.numeric_version" in package "base"
>>> Tracing function "is.na.POSIXlt" in package "base"
>>> [1] "is.na.data.frame"      "is.na.numeric_version" "is.na.POSIXlt"
>>>> z <- strptime("5/3/1992", format="%m/%d/%Y")
>>>> is.na(z)
>>> Tracing is.na.POSIXlt(z) on entry
>>>  is.na: class(x)= POSIXlt POSIXt
>>> [1] FALSE
>>>> str(unclass(z))
>>> List of 9
>>>  $ sec  : num 0
>>>  $ min  : int 0
>>>  $ hour : int 0
>>>  $ mday : int 3
>>>  $ mon  : int 4
>>>  $ year : int 92
>>>  $ wday : int 0
>>>  $ yday : int 123
>>>  $ isdst: int 1
>>>
>>>
>>>
>>> Bill Dunlap
>>> Spotfire, TIBCO Software
>>> wdunlap tibco.com  
>>>
>>>> -----Original Message-----
>>>> From: r-help-bounces at r-project.org 
>>>> [mailto:r-help-bounces at r-project.org] On Behalf Of 
>> Alexander Shenkin
>>>> Sent: Wednesday, June 22, 2011 11:41 AM
>>>> To: Sarah Goslee; r-help at r-project.org
>>>> Subject: Re: [R] strange date problem - May 3, 1992 is NA
>>>>
>>>> On 6/22/2011 1:34 PM, Sarah Goslee wrote:
>>>>> On Wed, Jun 22, 2011 at 2:28 PM, David Winsemius 
>>>> <dwinsemius at comcast.net> wrote:
>>>>>>
>>>>>> On Jun 22, 2011, at 2:03 PM, Sarah Goslee wrote:
>>>>>>
>>>>>>> Hi,
>>>>>>>
>>>>>>> On Wed, Jun 22, 2011 at 11:40 AM, Alexander Shenkin 
>>>> <ashenkin at ufl.edu>
>>>>>>> wrote:
>>>>>>>>>
>>>>>>>>> is.na(strptime("5/2/1992", format="%m/%d/%Y"))
>>>>>>>>
>>>>>>>> [1] FALSE
>>>>>>>>>
>>>>>>>>> is.na(strptime("5/3/1992", format="%m/%d/%Y"))
>>>>>>>>
>>>>>>>> [1] TRUE
>>>>>>>
>>>>>>> I can't reproduce your problem on R 2.13.0 on linux:
>>>>>>
>>>>>> I also cannot reproduce it on a Mac with 2.13.0 beta
>>>>>
>>>>> Which strongly suggests that you should start by upgrading your R
>>>>> installation if at all possible.
>>>>>
>>>>> I'd also recommend trying it on a default R session, with no extra
>>>>> packages loaded, and no items in your workspace. It's 
>> possible that
>>>>> something else is interfering.
>>>>>
>>>>> On linux, that's achieved by typing R --vanilla at the 
>> command line.
>>>>> I'm afraid I don't know how to do it for Windows, but should be
>>>>> similarly straightforward.
>>>>>
>>>> Thanks Sarah.  Still getting the problem.  I should surely 
>>>> upgrade, but
>>>> still, not a bad idea to get to the bottom of this, or at 
>>>> least have it
>>>> documented as a known issue.  BTW, I'm on Windows 7 Pro x64.
>>>>
>>>> (running Rgui.exe --vanilla):
>>>>
>>>>> is.na(strptime("5/3/1992", format="%m/%d/%Y"))
>>>> [1] TRUE
>>>>
>>>>> is.na(strptime("5/2/1992", format="%m/%d/%Y"))
>>>> [1] FALSE
>>>>
>>>>> sessionInfo()
>>>> R version 2.12.1 (2010-12-16)
>>>> Platform: i386-pc-mingw32/i386 (32-bit)
>>>>
>>>> locale:
>>>> [1] LC_COLLATE=English_United States.1252
>>>> [2] LC_CTYPE=English_United States.1252
>>>> [3] LC_MONETARY=English_United States.1252
>>>> [4] LC_NUMERIC=C
>>>> [5] LC_TIME=English_United States.1252
>>>>
>>>> attached base packages:
>>>> [1] stats     graphics  grDevices utils     datasets  
>> methods   base
>>>>
>>>> ______________________________________________
>>>> R-help at 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.
>>>>
>>



More information about the R-help mailing list