[R] Bug in as.POSIXct regarding AM/PM

David Winsemius dwinsemius at comcast.net
Fri Oct 8 14:47:58 CEST 2010


On Oct 8, 2010, at 5:54 AM, Ted Zeng (曾振兴) wrote:

>
> Dear All,
>
> I encounted in a problem with as.POSIXct() function.
>
>> as.POSIXct("2009/03/26 01:00:00 AM" , format="%Y/%m/%d %I:%M:%S %p")
> [1] NA
>> as.POSIXct("2009/03/26 02:00:00 PM" , format="%Y/%m/%d %I:%M:%S %p")
> [1] NA
>
> I have tried this in the R version 2.11.1,  R version 2.10.1  and R  
> version
> 2.9.2 . They all does not work. The operation system is win7.
>

Cannot reproduce on R 2.11.1 Mac OSX 10/5/8
R version 2.11.1 Patched (2010-06-14 r52281)
 > as.POSIXct("2009/03/26 01:00:00 AM" , format="%Y/%m/%d %I:%M:%S %p")
[1] "2009-03-26 01:00:00 EDT"
 > as.POSIXct("2009/03/26 02:00:00 PM" , format="%Y/%m/%d %I:%M:%S %p")
[1] "2009-03-26 14:00:00 EDT"

Is this a "daylight savings" time switch in your locale? Those  
switches generally occur at night (suggested by your 1AM NA and not by  
the 2PM value) but my experience is limited to the US so I don't know  
all possibilities.

You have not included the at a minimum information requested in the  
Posting Guide:

?sessionInfo

This seems likely due to your setup or possibly some sort of encoding  
issue that might be easier to reproduce with the results of sessionInfo.


-- 
David Winsemius, MD
West Hartford, CT

 > sessionInfo()
R version 2.11.1 Patched (2010-06-14 r52281)
x86_64-apple-darwin9.8.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8



More information about the R-help mailing list