[R] How to handle missing value as first item in yearmon (zoo package)

Marshall Feldman marsh at uri.edu
Fri Mar 19 14:36:49 CET 2010


Hi,

Some time series have missing values in the time index. For example 
historical data on business cycles will typically date them from peak to 
trough, but some information may be missing. In most cases, this does 
not cause trouble,
but if the first date is missing (e.g., we know the date of the first 
trough but not the earlier peak), we want the first element in a list of 
dates to be NA. Using yearmon, this causes trouble. Consider this:

 > x <- as.yearmon("March 2010","%B %Y")
 > y <- c(x,NA)
 > z <- c(NA,x)
 > y <- yearmon(y)
 > z <- yearmon(z)
 > y
         [1] "Mar 2010" NA
 > z
     Error in charToDate(x) :
       character string is not in a standard unambiguous format

Can someone explain how to make an object of type yearmon with a missing 
value in its first element?

Thanks.

     Marsh Feldman



More information about the R-help mailing list