rmeantsibble

Mean of a tsibble


I want to compute the mean of each series within a given tsibble. This is my code:

library(tsibble)

data <- tibble(
  Time = seq(as.Date("2020-01-01"), by = "1 months", length.out = 4),
  Series1 = c(3, 4, 1, 2), Series2 = c(0, 1, 2, 3)
)
ts <- as_tsibble(data, index = Time)

print(ts)
print(colMeans(ts))

It gives me

Error in colMeans(ts) : 'x' must be numeric

(This is the same error as with colMeans(data).)

Why doesn't tsibble overload colMeans to ignore the date index?
What else can I use?

(This is with R 4.0.4, tsibble 1.1.4.)


Solution

  • My own answers: