【发布时间】:2018-09-17 07:57:11
【问题描述】:
f1 f2
3 11/2/16 56.25
5 11/3/16 56.25
7 11/4/16 111.00
10 12/5/16 13.00
16 11/8/16 35.00
19 11/9/16 415.21
22 11/10/16 280.00
23 12/10/16 817.00
24 10/11/16 830.00
25 11/11/16 644.00
28 11/12/16 90.00
31 2/1/17 250.00
33 3/1/17 45.00
34 3/1/17 184.00
35 4/1/17 578.16
36 4/1/17 160.00
37 5/1/17 21.00
39 6/1/17 352.00
41 6/1/17 2089.00
44 7/1/17 855.00
45 8/1/17 488.00
46 8/1/17 573.00
47 8/1/17 654.00
50 9/1/17 1995.00
55 11/1/17 115.00
56 11/1/17 2147.00
57 12/1/17 74.00
59 12/1/17 1431.00
60 1/2/17 50.00
62 2/2/17 657.00
67 5/2/17 629.00
71 6/2/17 23.00
75 8/2/17 350.00
77 8/2/17 1449.00
79 9/2/17 364.00
80 9/2/17 1185.00
85 11/2/17 405.00
86 11/2/17 4725.00
87 12/2/17 50.00
88 12/2/17 202.00
89 12/2/17 2377.00
90 1/3/17 500.00
91 2/3/17 600.00
93 3/3/17 60.00
94 3/3/17 14.00
具有上述数据集名称 dat.filtered。此数据必须转换为时间序列数据。 尝试此代码给出错误:
library(xts)
xts.sample <- xts(dat.filtered$f2, order.by = as.Date(dat.filtered$f1, "%d/%m/%Y"))
给出这个错误:
xts(dat.filtered$f2, order.by = as.Date(dat.filtered$f1, "%d/%m/%Y")) 中的错误: “order.by”不能包含“NA”、“NaN”或“Inf”
如何消除此错误。
【问题讨论】:
-
你不需要在
subset里面使用$;但它仍应按f2 > 0过滤条目。声明“但没有得到想要的结果” 不是很具体。什么没用?无论哪种方式,我都会在下面给出一个示例解决方案。
标签: r time-series