如何在 R 中将 as_tibble() 格式的时间序列数据转换为 as_tsibble() 格式?

How to transform an as_tibble() format time series data into an as_tsibble() format in R?

到目前为止我得到的结果如下,这是一个 'tibble' 格式。

但是,由于这是一组时间序列,我希望将这个结果x转换成'tsibble'格式后记。

有人知道我还需要做什么吗?

我试过使用

x <- function_name(n.ts = 3, freq = 12, nComp = 2, n = 120,output_format = "list")
as_tsibble(x)

错误说

另一个尝试和错误 内容应该显示类似这样的东西

'x' 是具有多个组件的 list。我们可以用 map 遍历 list,提取 'x' 组件并将其转换为 tsibble

library(dplyr)
library(purrr)
x1 <- map(x,  ~ as_tsibble(.x$x))
x1
#$N1
# A tsibble: 120 x 2 [1M]
#      index value
#      <mth> <dbl>
# 1 0001 Jan  186.
# 2 0001 Feb  184.
# 3 0001 Mar  189.
# 4 0001 Apr  188.
# 5 0001 May  193.
# 6 0001 Jun  189.
# 7 0001 Jul  192.
# 8 0001 Aug  194.
# 9 0001 Sep  194.
#10 0001 Oct  196.
# … with 110 more rows

#$N2
# A tsibble: 120 x 2 [1M]
#      index value
#      <mth> <dbl>
# 1 0001 Jan  18.4
# 2 0001 Feb  16.0
# 3 0001 Mar  16.9
# ...

此处,索引部分由列名 ('Month') 创建,由于没有关于 'year' 的信息,它以 '0001'

开头

数据

library(gratis)
x <- generate_ts(n.ts = 3, freq = 12, nComp = 2, n = 120)