这段代码中 yearmonth() 和 as_tsibble() 的目的是什么?

What is the purpose of yearmonth() and as_tsibble() in this code?

在这段代码中,DK是一个数据集:

现在,这里的 yearmonth() 和 as_tsibble() 的功能是什么?

DK["date"] = yearmonth(DK$date)
DK_ts = as_tsibble(DK, index=date)

这两个函数都来自 R 包 tsibble,它是时间序列 tibble 的缩写。它们表示时间结构化的纵向表,其中每一行都是一个时间点。请参阅文档 here and here

x <- seq(as.Date("2016-01-01"), as.Date("2016-12-31"), by = "1 month")
yearmonth(x)
# <yearmonth[12]>
# [1] "2016 Jan" "2016 Feb" "2016 Mar" "2016 Apr" "2016 May" "2016 Jun" "2016 Jul" "2016 Aug" "2016 Sep" "2016 Oct" "2016 Nov" "2016 Dec"

as_tsibble 将一个普通的数据帧转换成一个知道时间点的数据帧。