从R中的列表构建时间序列?

时间:2016-12-01 13:29:03

标签: r list time-series lapply

您好我正在尝试通过将ts()函数应用于我拥有的数据帧列表来创建时间序列对象列表。我的数据帧列表名为whisk.basic.lst,它包含69个数据帧。我正在展示它如下所示:

    > str(whisk.basic.lst)
 $ SI_VALUES_IMV_EU28_INTRA  :List of 12
  ..$ 220830  : num [1:74] 218674 255317 327377 363219 335267 ...
  ..$ 22083011: num [1:74] 9363 10129 19672 20631 10403 ...
  ..$ 22083019: num [1:74] 0 1978 0 0 7116 ...
  ..$ 22083030: num [1:74] 3837 15684 14588 20487 30870 ...
  ..$ 22083041: num [1:74] 18979 5123 7176 36842 9390 ...
  ..$ 22083049: num [1:74] 688 0 0 0 0 0 0 0 0 0 ...
  ..$ 22083061: num [1:74] 0 0 3452 4225 96 ...
  ..$ 22083069: num [1:74] 0 0 0 40 0 0 7520 0 0 0 ...
  ..$ 22083071: num [1:74] 139915 204803 256095 218105 185088 ...
  ..$ 22083079: num [1:74] 0 3219 0 0 3381 ...
  ..$ 22083082: num [1:74] 45892 14381 26394 62889 88527 ...
  ..$ 22083088: num [1:74] 0 0 0 0 396 0 0 0 642 105 ...
 $ SK_VALUES_IMV_EU28_EXTRA  :List of 11
  ..$ 220830  : num [1:74] 7155 12311 237 2705 7419 ...
  ..$ 22083011: num [1:74] 0 0 0 0 35 0 0 0 122 0 ...
  ..$ 22083019: num [1:74] 0 0 0 0 0 0 0 0 0 0 ...
  ..$ 22083030: num [1:74] 0 0 0 0 935 235 732 0 669 0 ...
  ..$ 22083041: num [1:74] 0 0 0 0 2603 ...
  ..$ 22083049: num [1:74] 0 0 0 0 0 0 0 0 0 0 ...
  ..$ 22083061: num [1:74] 0 0 0 0 0 0 0 0 0 0 ...
  ..$ 22083071: num [1:74] 0 0 0 0 27 0 546 0 0 0 ...
  ..$ 22083079: num [1:74] 0 0 0 0 0 0 0 0 0 0 ...
  ..$ 22083082: num [1:74] 7155 12311 237 2705 3819 ...
  ..$ 22083088: num [1:74] 0 0 0 0 0 0 0 0 0 0 ...
 $ SK_VALUES_IMV_EU28_INTRA  :List of 11
  ..$ 220830  : num [1:74] 380007 459653 155033 205879 297446 ...
  ..$ 22083011: num [1:74] 26772 68577 8585 24567 17996 ...
  ..$ 22083019: num [1:74] 0 0 0 0 0 0 0 0 0 0 ...
  ..$ 22083030: num [1:74] 60521 15068 1830 9788 5557 ...
  ..$ 22083041: num [1:74] 110461 71551 66317 47354 46776 ...
  ..$ 22083049: num [1:74] 100 19718 4115 201 201 ...
  ..$ 22083061: num [1:74] 0 29706 0 0 8177 ...
  ..$ 22083071: num [1:74] 418 21760 3138 68164 46300 ...
  ..$ 22083079: num [1:74] 0 738 0 738 2213 ...
  ..$ 22083082: num [1:74] 181487 186179 68737 53360 170226 ...
  ..$ 22083088: num [1:74] 248 46356 2311 1707 0 ...

Ts.whisk.lst <- lapply(whisk.basic.lst, function(x) ts(x, frequency= 12, start=c(2010,1)))

我收到以下错误:

Error in ts(x, frequency = 12, start = c(2010, 1)) : 
  'ts' object must have one or more observations
Called from: ts(x, frequency = 12, start = c(2010, 1))

我以前从我的数据框创建时间序列没有任何问题。但是,由于我创建了这些数据帧的列表,我遇到了这个问题。有谁知道为什么?

0 个答案:

没有答案