[英]How to transform an as_tibble() format time series data into an as_tsibble() format in R?
so far the result I get is as below, which is a 'tibble' format.到目前为止,我得到的结果如下,这是一种“tibble”格式。
However, as this is a group of time series, I wish to transform this result x
into a 'tsibble' format afterwords.但是,由于这是一组时间序列,我希望将这个结果x
转换为 'tsibble' 格式的后记。
Anyone know what further step I need to do?有谁知道我需要做什么进一步的步骤?
I tried using我尝试使用
x <- function_name(n.ts = 3, freq = 12, nComp = 2, n = 120,output_format = "list")
as_tsibble(x)
Another trying & error另一个尝试和错误 The content should display something similar to this内容应显示与此类似的内容
The 'x' is a list
with multiple components. 'x' 是一个包含多个组件的list
。 We can loop over the list
with map
, extract the 'x' component and convert it to tsibble
我们可以使用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
# ...
Here, the index part is created by the column name ('Month') and as there was no information regarding the 'year', it started with '0001'在这里,索引部分是由列名('Month')创建的,由于没有关于 'year' 的信息,它以 '0001' 开头
library(gratis)
x <- generate_ts(n.ts = 3, freq = 12, nComp = 2, n = 120)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.