Re: [R] strptime format argument

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Mon, 28 Apr 2008 23:08:27 +0100 (BST)

On Mon, 28 Apr 2008, Hutchinson,David [PYR] wrote:

> I am getting an unanticipated result attempting to format a datetime
> string
>
> date1 <- strptime('2005 297 1030 35', '%Y %j %H%M %S') # returns
> "2005-10-24 10:12:35"
> date2 <- strptime('2005 297 912 35', '%Y %j %H%M %S') # returns NA
>
> Are there any ways to adjust the format argument (e.g., '%H') to accept
> one or two digit hours?

That's not the issue:

> strptime('2005 297 9 12 35', '%Y %j %H %M %S')
[1] "2005-10-24 09:12:35"

The issue is that 91 is an invalid value for %H -- it reads from left to right

> strptime('2005 297 112 35', '%Y %j %H%M %S')
[1] "2005-10-24 11:02:35"

You will need to preprocess the string if you want another interpretation.

-- 
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

______________________________________________
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.
Received on Mon 28 Apr 2008 - 22:11:21 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 28 Apr 2008 - 22:30:32 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive