[R] time series contains internal NAs error

Achim Zeileis Achim.Zeileis at wu-wien.ac.at
Mon Jan 19 15:47:40 CET 2009


On Mon, 19 Jan 2009, stephen sefick wrote:

> It would be helpful to have a reproducible dataset to track down what
> is happening.

True.

Although in this case it's relatively easy to guess what went wrong. 
The user probably has some irregular series, for example daily with 
missing days:
    x <- xts(rnorm(10), as.Date("2009-01-19") + c(0:4, 7:11))

>> I seem to have a peculiar problem. When using  time series data, I get
>> the following error when running the acf and pacf function.
>> Using the function acf(dtxts,plot= TRUE,xaxt = "n",col="red",na.action
>> = na.omit) (where dtxts is a time series object created with package
>> "xts" ) results in the error below.

acf() just works with regular time series of class "ts". Everything else 
is coerced via as.ts(). This is where the problem is created for your data 
as the error message conveyed:

>> Error in na.omit.ts(as.ts(x)) : time series contains internal NAs

as.ts(x) detects that there is an underlying regularity (1-day steps) if 
you include two internal NAs (the weekend).

na.omit(as.ts(x)) cannot omit internal NAs because the "ts" class cannot 
represent such an object. Even if it could, acf() couldn't compute the ACF 
with internal mising data.

Some people just ignore the weekend effect (i.e., assume that the Mon-Fri 
correlation is the same as Tue-Mon). If one wants to do this, it can be 
obtained via acf(coredata(x)).

>> The above error is seen in R 2.8.0 running on Linux.
>>
>> The same function does not yield any error in R 2.8.0 on a Windows system.

I'm fairly certain it does.
Z




More information about the R-help mailing list