SteffenMoritz/imputeTS

Getting Error on part of my time series

MehrdadVaredi opened this issue · 3 comments

Hi Steffen and Bartz,

I got an error after running the na_kalman from imputeTS library. This function works on part of the xts time series object I was testing, although it returns an error if applied on all of it.

The error is:

Error in if (frequency > 1 && 0 < (d <- abs(frequency - round(frequency))) && :
missing value where TRUE/FALSE needed

This is the structure of the its object:

str(SCADA_xts)

An ‘xts’ object on 2017-04-18 20:00:00/2019-07-31 20:00:00 containing:
Data: num [1:64120, 1] 198348 198618 195981 188490 186822 ...
Indexed by objects of class: [POSIXct,POSIXt] TZ: America/Toronto
xts Attributes:
NULL

Do you have any idea what might be wrong with my data?

Thanks and best regards,

Mehrdad

Thanks for reporting! 👍

Oh, strange error. On first sight I'd assume it has something to do with the xts object.

Can you try

    test <-  as.data.frame(coredata(SCADA_xts))
    na_kalman(test)

To see if it works, when it is not a xts object.

You were right Steffen! I get no errors if I apply na_kalman on the data.frame ! Thank you!

Kind regards,
Mehrdad

Sounds great 👍
Always complicated, everybody uses different time series objects in R....zoo, xts, tsibble, tibble, data.frame, vector.

imputeTS is written for vector, data.frame and ts inputs.
But I try to keep it compatible with all of the different possible time series objects.

Still, as you can see, for time to time errors occur for certain edge cases. This one seems to be present specifically for na_kalman in combination with xts objects. I'll additionally have a look in the upcoming days if I can prevent this error for xts objects.