[R] Can strptime handle milliseconds or AM/PM?

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu Jan 17 09:22:47 CET 2013


On 17/01/2013 07:59, e-letter wrote:
> Readers,
>
> Responding to an old post
> (http://tolstoy.newcastle.edu.au/R/e2/help/07/06/18850.html), and
> using the example in the manual:
>
> monthextract<-strptime("20/2/06 11:16:16.683", "%m")
> monthextract
> [1] NA
>
> Why is the result 'NA' and not '2'?

Because you have not specified a complete date-time, only month = 20 
(which is invalid).

The help page actually has

      z <- strptime("20/2/06 11:16:16.683", "%d/%m/%y %H:%M:%OS")

I guess you were looking for

strftime(z, "%m")

which gives "02" on my system (it may be platform-specific)

or

z$mon + 1

>
> --
> r2151
>
> ______________________________________________
> 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.
>


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



More information about the R-help mailing list