我想询问有关将数据框(或 tibble)转换为 tsibble 的最有效方法的建议。
数据框在第一列中有日期,所有其他列代表各种时间序列,并在相应日期给出值。我想有效地创建一个 tsibble,其中键 = 每个时间序列的名称,索引 = 每个日期。
所以输出将是一个 tsibble,如下所示:
Key Index Value
TimeSeriesOne FirstDate Value TimeSeriesOne on first date
TimeSeriesOne SecondDate Value TimeSeriesOne on second date
......................................................................
TimeSeriesOne LastDate Value TimeSeriesOne on last date
TimeSeriesTwo FirstDate Value TimeSeriesTwo on first date
......................................................................
TimeSeriesN LastDate Value TimeSeriesN on last date
输入数据示例:
numRows <- 15
startDate <- lubridate::as_date('2018-06-10')
endDate <- startDate + base::months(x = numRows-1)
theDates <- base::seq.Date(
from = startDate,
to = endDate,
by = "month")
inputData <- tibble::tibble(
"Dates" = theDates,
"SeriesOne" = stats::rnorm(numRows),
"SeriesTwo" = stats::rnorm(numRows),
"SeriesThree" = stats::rnorm(numRows),
"SeriesFour" = stats::rnorm(numRows))