【发布时间】:2021-05-24 12:41:00
【问题描述】:
我有多个变量的数据。我的数据str如下:
tibble [2,859 × 92] (S3: tbl_df/tbl/data.frame)
$ Date : POSIXct[1:2859], format: "2010-04-01" "2010-04-
02" "2010-04-05" "2010-04-06" ...
$ Num : num [1:2859] 1 2 3 4 5 6 7 8 9 10 ...
$ Price : num [1:2859] 3158 3158 3159 3148 3119 ... `
我想将数据转换为时间序列格式。我尝试了一些解决方案,但没有奏效(例如,How can I transform a dataframe with POSIXct dates into a time series? 我收到此错误: DF <- data.frame(FinDat = date, FinDat$Price = sample(100, length(date), TRUE)) Error: unexpected '=' in "DF <- data.frame(FinDat = date, FinDat$Price =")
我的数据的一个例子是:
structure(list(Date = structure(c(1270080000, 1270166400, 1270425600,
1270512000, 1270598400, 1270684800, 1270771200, 1271030400, 1271116800,
1271203200), tzone = "UTC", class = c("POSIXct", "POSIXt")),
Price = c(3157.957, 3157.957, 3158.681, 3148.222, 3118.709,
3145.347, 3129.263, 3161.251, 3166.183, 3164.966)), row.names = c(NA,
-10L), class = c("tbl_df", "tbl", "data.frame"))
我想使用autoplot函数和auto.arima
【问题讨论】:
-
“转换为时间序列格式” 可能是几件事,具体取决于您打算使用的包/功能。 “尝试了一些解决方案,但没有奏效” 不能帮助我们帮助您修复代码。请附上您尝试过的代码,以便我们帮助您修复它。
-
@r2evans 非常感谢您的评论。它改善了我的问题。
-
虽然错误很明显(不要使用
FinDat$Price = ...inside ofdata.frame),但我认为看看你尝试了什么会很好。 -
目前尚不清楚您在寻找什么输出,但这会将其转换为动物园系列:
library(zoo); z <- read.zoo(dat) -
@G.Grothendieck 非常感谢您的帮助。我只想使用
autoplot绘制数据并将Arima 模型拟合到它。
标签: r time-series posixct