我有一個數據幀「GG」,看起來像這樣:轉換數據參差不齊時間[時間戳]系列常規時間系列:R
> head(gg)
timestamps value
1 2017-04-25 16:52:00 -0.4120000
2 2017-04-25 16:53:00 -0.4526667
3 2017-04-25 16:54:00 -0.4586667
4 2017-04-25 16:55:00 -0.4606667
5 2017-04-25 16:56:00 -0.5053333
6 2017-04-25 16:57:00 -0.5066667
我需要繪製這是一個時間序列數據做預測。步驟如下:
1)gg$timestamps <- as.POSIXct(gg$timestamps, format = "%Y-%m-%d %H-%M-%S") #changing "Timestamps" column 'factor' to 'as.POSIXct'.
2)gg.ts <- xts(x=gg$value, order.by = gg$timestamps) #converting the dataframe to time series (Non Regular Time series)
現在我想這個gg.ts
轉換爲常規時間序列預測做這樣的(Forecasting time series data) 但我不知道如何將時間戳值系列添加到ts
函數中。當我嘗試它拋出錯誤:
> gg.xts <- ts(gg.ts, frequency = '1', start = c(2017-04-25 16:52:00,171))
Error: unexpected numeric constant in "gg.xts <- ts(gg.ts, frequency = '1', start = c(2017-04-25 16"
我有我的整個問題清楚地列在這裏。 https://stackoverflow.com/questions/43627826/plotting-time-series-data-r-plotly-timestamp-values 請幫幫我。謝謝
感謝你好很多的答覆。但我希望這個時間戳值使用「ts」(例如:'x = xts(res,order.by = res $ x),x.ts = ts(x,freq = 1, start = c(2017-04-25 16:48:00,191))'。這個x.ts拋出錯誤,正如我前面提到的那樣,該圖顯示了我的圖表中的一些隨機值,它應該顯示time-tamp value。請參考這個[link](http://stackoverflow.com/questions/10302261/forecasting-time-series-data) – dhinar
你得到的錯誤是因爲'start'接受了'numeric ',而不是你輸入的內容 – theArun
有沒有辦法將這些時間戳值添加到'開始'?becoz我想要這些時間戳值,因爲我的x軸縮放到預測圖上。希望你能明白我的觀點 – dhinar