[R] AM/PM strptime %p failing 2.11.0 WinXP

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon May 24 07:58:18 CEST 2010


On Mon, 24 May 2010, Samuel Dennis wrote:

> I am attempting to import dates in the following format to R:
> 5/20/2010 6:45:32 PM
>
> Unfortunately I am unable to get the AM/PM function (%p) to work correctly
> under either 2.11.0 or 2.8.1.
>> strptime("5/20/2010 6:45:32 PM", "%m/%d/%Y %I:%M:%S %p")
> [1] NA
>
> but
>> strptime("5/20/2010 6:45:32", "%m/%d/%Y %I:%M:%S")
> [1] "2010-05-20 06:45:32"
>
> showing that the problem is with %p.
>
> I could only find one previous mention of this issue in the archives (
> http://tolstoy.newcastle.edu.au/R/e2/help/06/11/6272.html) , which provided

That was a different issue (missing minutes and seconds) and in 
any case the underlying code has been replaced in the intevening 3.5 
years.

> no solution beyond upgrading R (which I have done), and just suggested it
> was a problem with that particular installation of R and Windows.
>
> What could I do to get this function working on my Windows XP machine?

We don't have the 'at a minimum' information asked for in the posting 
guide, but your example works for me on my Windows XP machine.  Note 
that the use of %p differs by language settings (and I have seen 
reports where that was the issue).  I used

> sessionInfo()
R version 2.11.0 (2010-04-22)
i386-pc-mingw32

locale:
[1] LC_COLLATE=English_United Kingdom.1252
[2] LC_CTYPE=English_United Kingdom.1252
[3] LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United Kingdom.1252

in the Europe/London timezone.

> Thankyou,
>
> Samuel Dennis
> sjdennis3 at gmail.com
>
> 	[[alternative HTML version deleted]]


-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

> sessionInfo()
R version 2.11.0 (2010-04-22)
i386-pc-mingw32

locale:
[1] LC_COLLATE=English_United Kingdom.1252
[2] LC_CTYPE=English_United Kingdom.1252
[3] LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United Kingdom.1252

a



More information about the R-help mailing list