[R] NAs in chron objects

Prof Brian Ripley ripley at stats.ox.ac.uk
Fri May 18 16:37:30 CEST 2001

On Fri, 18 May 2001, Markus Jantti wrote:

> Dear All:
> I am having some trouble with date variables when NAs are present. The
> following example illustrates (see below for output of version):


> dates() correctly produces the first NA's but becomes confused when
> strings with times start appearing. The below examples suggest the
> POSIXct class in the base package also has some trouble.

The trouble is your end: the error message means what it says,
and is explained the help page.  As the help page says,
specify the precise format, by in your case

as.POSIXct(strptime(minor.test[1:10], "%Y-%m-%d"))
 [1] "NA"             "NA"             "1988-02-08 GMT" "1988-02-08 GMT"
 [5] "NA"             "1987-11-23 GMT" "1988-09-03 BST" "1991-10-15 BST"
 [9] "1992-01-14 GMT" "1992-02-18 GMT"

Unless you specify the format, there is no way to distinguish invalid
entries from strings you mean to be NA, so the guessing algorithm give

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 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list