[R] strange date problem - May 3, 1992 is NA
Alexander Shenkin
ashenkin at ufl.edu
Wed Jun 22 20:09:03 CEST 2011
On 6/22/2011 1: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:
>
>> strptime("5/2/1992", format="%m/%d/%Y")
> [1] "1992-05-02"
>> is.na(strptime("5/2/1992", format="%m/%d/%Y"))
> [1] FALSE
>> strptime("5/3/1992", format="%m/%d/%Y")
> [1] "1992-05-03"
>> is.na(strptime("5/3/1992", format="%m/%d/%Y"))
> [1] FALSE
>
> My suspicion is that you imported the data from a spreadsheet and
> there's some formatting glitch that's not showing up. If you type the
> string "5/3/1992" into the command by hand, do you still get the same
> result?
Copy and pasting the above lines reproduces the problem on my setup.
> If so, then we need to know your OS and version of R, at least.
> sessionInfo()
R version 2.12.1 (2010-12-16)
Platform: i386-pc-mingw32/i386 (32-bit)
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United
States.1252 LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] grid grDevices datasets splines graphics stats tcltk
utils methods base
other attached packages:
[1] ggplot2_0.8.9 proto_0.3-8 reshape_0.8.4 plyr_1.4
svSocket_0.9-51 TinnR_1.0.3 R2HTML_2.2 Hmisc_3.8-3
survival_2.36-2
loaded via a namespace (and not attached):
[1] cluster_1.13.2 digest_0.4.2 lattice_0.19-17 svMisc_0.9-61
tools_2.12.1
>
>> Any idea what's going on with this? Running strptime against all dates
>> from around 1946, only 5/3/1992 was converted as "NA". Even stranger,
>> it still seems to have a value associated with it (even though is.na
>> thinks it's NA):
>>
>>> strptime("5/3/1992", format="%m/%d/%Y")
>> [1] "1992-05-03"
>
> This makes no sense to me.
>
> Sarah
>
>
More information about the R-help
mailing list