[英]R Using timeSeries::timeSeries()
誰能指出為什么代碼塊(1)有效但塊(2)無效?
代碼塊(1):
library(timeSeries)
data <- matrix(round(rnorm(24), 4), nrow = 12)
dates <- seq(as.Date("2009-01-01"), by = "month", length.out = 12)
ts <- timeSeries(data, dates)
代碼塊(2):
library(timeSeries)
data <- matrix(round(rnorm(50), 4), nrow = 10)
dput(dates)
structure(list(date = structure(c(14977, 14978, 14979, 14980,
14981, 14984, 14985, 14986, 14987, 14988), class = "Date")), row.names = c(NA,
-10L), class = c("tbl_df", "tbl", "data.frame"))
ts <- timeSeries(data, dates)
R 拍了拍我的手:
警告消息:In whichFormat(charvec[1]): 字符串不是標准的明確格式
從?timeSeries
, charvec
是一個向量。 在第二種情況下,您向它傳遞了一個 tibble/dataframe,這就是您收到錯誤的原因。 嘗試:
library(timeSeries)
ts <- timeSeries(data, dates$date)
ts
GMT
# TS.1 TS.2 TS.3 TS.4 TS.5
#2011-01-03 0.3524 -0.7522 -0.8783 -1.2821 0.4415
#2011-01-04 -0.4300 -0.3055 -0.1887 -0.2559 -1.5267
#2011-01-05 -0.6599 0.3771 -0.4605 -1.9424 -1.5447
#2011-01-06 -0.6139 0.4265 -0.0856 1.0123 -0.5640
#2011-01-07 0.4265 -0.9353 0.3372 1.1031 0.3113
#2011-01-10 2.1332 -0.0201 -1.1552 -0.8441 0.0602
#2011-01-11 0.4315 1.3390 0.0306 -0.9695 1.2771
#2011-01-12 -0.4005 -0.5906 1.4297 -0.4055 0.1387
#2011-01-13 -1.9644 0.3039 -2.0004 -0.7983 -1.5974
#2011-01-14 0.8797 0.6690 -1.8821 0.0437 -0.2202
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.