Hi there, Am I missing something? The "%p" format, which should match against AM/PM, seems to be broken in R 2.3.1 running on Windows XP SP2. For example, the following fails > strptime("10AM", "%I%p") [1] NA whereas the this works as you would expect, but is ambiguous > strptime("10", "%I") [1] "2006-11-30 10:00:00" Does this error reproduce on other machines, or is it something wrong with my setup? Cheers, Edward
Prof Brian Ripley
2006-Nov-30 07:45 UTC
[R] strptime - %p format doesn't seem to be working
On Thu, 30 Nov 2006, Edward Abraham wrote:> Hi there, > > Am I missing something? The "%p" format, which should match against > AM/PM, seems to be broken in R 2.3.1 running on Windows XP SP2. For > example, the following fails > > > strptime("10AM", "%I%p") > [1] NA > > > whereas the this works as you would expect, but is ambiguous > > strptime("10", "%I") > [1] "2006-11-30 10:00:00" > > Does this error reproduce on other machines, or is it something wrong > with my setup?My Windows XP, R 2.4.0 in English gives> strptime("10AM", "%I%p")[1] "2006-11-30 10:00:00" So, it is a problem specific to you at least for R 2.4.0 (and the posting guide asked you to update before posting). However, the help both warns about this being locale-specific and also If the date string does not specify the date completely, the returned answer may be system-specific. The most common behaviour is to assume that unspecified seconds, minutes or hours are zero, and a missing year, month or day is the current one. If it specifies a date incorrectly, reliable implementations will give an error and the date is reported as 'NA'. so what you say should work is explicitly documented to not necessarily do so. -- 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