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

问题描述

到目前为止,我得到的结果如下所示,它是“小标题”格式。

但是,由于这是一组时间序列,因此我希望将此结果x转换为“ tsibble”格式的后缀。

任何人都知道我还需要做什么?

enter image description here

我尝试使用

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

错误说

enter image description here

另一个尝试与错误

enter image description here

内容应显示与此类似的内容

enter image description here

解决方法

“ x”是具有多个成分的list。我们可以用list遍历map,提取'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
# ...

在这里,索引部分是由列名(“月”)创建的,由于没有有关“年”的信息,因此它以“ 0001”开头

数据

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

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...