[R] POSIX Date-Time Classes and missing values

Bill Oliver wloliver at qwest.net
Sun Jun 24 20:17:05 CEST 2001

Is there a good method for dealing with missing values when using the POSIX
date-time classes?

I would like to convert character data with some missing values to dates, so
that I can calculate intervals of time. However, I'm having trouble figuring
out a good way to work with the missing values. Missing values cause
problems when converting to the POSIXct date-time class, as illustrated

> foobar
[1] "NA"                  "1992-02-27 22:29:56" "1992-01-14 01:03:30"
> as.POSIXct(foobar)
Error in fromchar(x) : character string is not in a standard unambiguous

Also, I haven't found a way to assign missing values to POSIX date-time
entries. For example, the following doesn't work.

> foodate
[1] "1992-02-27 22:29:56 Mountain Standard Time" "1992-01-14 01:03:30
Mountain Standard Time"
> foodate[1] <- NA
Error in as.POSIXct.default(value) : Don't know how to convert `value' to
class "POSIXct"

I'm prepared to convert the missing values to an arbitrary date and then
test for that date when the time intervals are to be calculated. This
method, however, seems very inelegant and prone to error--I'm hoping that
there is a better method.

The version of R that I'm using is 1.3.0 under Windows 2000.

Thanks!  Bill

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