我有一个由4个变量组成的数据,即日期,黄金价格,原油价格和美元在卢比。如下所示。
head(Gold)
DATE GOLD.PRICE CRUDE DOLLAR.INR
1 2006-01-04 533.9 63.42 44.705
2 2006-01-05 526.3 62.79 44.600
3 2006-01-06 539.7 64.21 44.320
4 2006-01-09 549.1 63.50 44.250
5 2006-01-10 544.3 63.37 44.185
6 2006-01-11 548.8 63.94 43.915
这是我的数据。
Gold <- structure(list(DATE = structure(c(13152, 13153, 13154, 13157,
13158, 13159), class = "Date"), GOLD.PRICE = c(533.9, 526.3,
539.7, 549.1, 544.3, 548.8), CRUDE = c(63.42, 62.79, 64.21, 63.5,
63.37, 63.94), DOLLAR.INR = c(44.705, 44.6, 44.32, 44.25, 44.185,
43.915)), class = "data.frame", .Names = c("DATE", "GOLD.PRICE",
"CRUDE", "DOLLAR.INR"), row.names = c(NA, -6L))
我想执行时间序列分析,因此我将数据框对象转换为时间序列对象。
Gold.ts <- ts(Gold,start=1)
head(Gold.ts)
DATE GOLD.PRICE CRUDE DOLLAR.INR
[1,] 13152 533.9 63.42 44.705
[2,] 13153 526.3 62.79 44.600
[3,] 13154 539.7 64.21 44.320
[4,] 13157 549.1 63.50 44.250
[5,] 13158 544.3 63.37 44.185
[6,] 13159 548.8 63.94 43.915
现在我如何理解每条记录对应的日期?转换为时间序列对象后如何提取日期?
答案 0 :(得分:1)
您可以使用动物园图书馆。
library(zoo)
as.yearmon(time(Gold.ts))
您将获得以下结果:
[1]&#34; Jan 0001&#34; &#34; Jan 0002&#34; &#34; Jan 0003&#34; &#34; Jan 0004&#34; &#34; Jan 0005&#34; &#34; Jan 0006&#34;