Closed bking124 closed 1 year ago
This sort of thing is super-annoying and arises because ts
objects store tsp
attributes in floating point rather than integers. The simplest solution is to make b
a plain vector:
b <- 1
a_fc$mean + b
Yes super-annoying is the right description! Took me a long time to realize what was happening. But appreciate the quick reply and thanks for the solution!
This is probably a very niche bug, and I'm not sure whether the error is with the ts package or the forecast package. However, I was able to isolate a simple working example. For a bit of background on how I arrived at this error: I was adapting code which forecasted a seasonally adjusted time series, then post-hoc added back in a forecast of the seasonal part. It was in this "adding back" process where the bug was created. Essentially, I tried to create a ts object using the start of the mean coming from a forecast object. Then I wanted to add this ts object to the forecast object mean, but I get a warning:
and the result is integer(0). A simple working example that creates this warning is below.
The mismatch seems to come from a floating point or other numeric type error, as can be seen by running these lines
which give output of
I'm sure I can fairly easily work around this now that I've isolated the error (probably using as.numeric, adding, and then making it a ts again), but still I thought it was worth raising a flag. Let me know if there's any detail I can add.