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. Thanks Ted -- View this message in context: http://r.789695.n4.nabble.com/Bug-in-as-POSIXct-regarding-AM-PM-tp2968076p2968076.html Sent from the R help mailing list archive at Nabble.com.
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
On Fri, Oct 8, 2010 at 5:54 AM, Ted Zeng (???) <zengzhenxing at gmail.com> 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.I can reproduce this on Windows Vista if I set the locale of LC_Time to Chinese. If its set to English then it works ok:> Sys.setlocale("LC_TIME", "Chinese")[1] "Chinese (Simplified)_People's Republic of China.936"> > Sys.getlocale("LC_TIME")[1] "Chinese (Simplified)_People's Republic of China.936"> > as.POSIXct("2009/03/26 01:00:00 AM" , format="%Y/%m/%d %I:%M:%S %p")[1] NA> > > Sys.setlocale("LC_TIME", "English")[1] "English_United States.1252"> > Sys.getlocale("LC_TIME") # check it[1] "English_United States.1252"> > 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"> > > R.version.string[1] "R version 2.11.1 Patched (2010-05-31 r52167)"> win.version()[1] "Windows Vista (build 6002) Service Pack 2" -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com
Hi,> Sys.setenv(TZ="PRC") > Sys.setlocale("LC_TIME", "Chinese")[1] "Chinese (Simplified)_People's Republic of China.936"> as.POSIXct("2009/03/26 01:00:00 ??" , format="%Y/%m/%d %I:%M:%S %p")[1] "2009-03-26 01:00:00 CST"> as.POSIXct("2009/03/26 01:00:00 ??" , format="%Y/%m/%d %I:%M:%S %p")[1] "2009-03-26 13:00:00 CST"> Sys.setlocale("LC_TIME", "American")[1] "English_United States.1252"> as.POSIXct("2009/03/26 01:00:00 AM" , format="%Y/%m/%d %I:%M:%S %p")[1] "2009-03-26 01:00:00 CST">2010/10/8 Ted Zeng (???) <zengzhenxing at gmail.com>:> > 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. > > Thanks > > Ted > -- > View this message in context: http://r.789695.n4.nabble.com/Bug-in-as-POSIXct-regarding-AM-PM-tp2968076p2968076.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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. > > >-- EI-JI Nakama <nakama (a) ki.rim.or.jp> "\u4e2d\u9593\u6804\u6cbb" <nakama (a) ki.rim.or.jp>
My locale information is as follows:> sessionInfo()R version 2.11.1 (2010-05-31) i386-pc-mingw32 locale: [1] LC_COLLATE=Chinese (Simplified)_People's Republic of China.936 [2] LC_CTYPE=Chinese (Simplified)_People's Republic of China.936 [3] LC_MONETARY=Chinese (Simplified)_People's Republic of China.936 [4] LC_NUMERIC=C [5] LC_TIME=Chinese (Simplified)_People's Republic of China.936 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] JGR_1.7-2 iplots_1.1-3 JavaGD_0.5-3 rJava_0.8-5 loaded via a namespace (and not attached): [1] tools_2.11.1 However, as Gabor said, If I set the locale time to "English". It works.> Sys.setlocale("LC_TIME", "English")[1] "English_United States.1252"> Sys.getlocale("LC_TIME")[1] "English_United States.1252"> as.POSIXct("2009/03/26 01:00:00 PM" , format="%Y/%m/%d %I:%M:%S %p")[1] "2009-03-26 13:00:00 CST" SO, What is the Problem? How to solve this problem. -- View this message in context: http://r.789695.n4.nabble.com/Bug-in-as-POSIXct-regarding-AM-PM-tp2968076p2969281.html Sent from the R help mailing list archive at Nabble.com.