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

Sarah Goslee sarah.goslee at gmail.com
Wed Jun 22 20:03:09 CEST 2011


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?

If so, then we need to know your OS and version of R, at least.

> 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


-- 
Sarah Goslee
http://www.functionaldiversity.org



More information about the R-help mailing list