使用 R 中的年、月和周从 lubridate 生成日期

makedate from lubridate with year, month, and week in R

我的数据包含年、月、周列。如何将其转换为 lubridate 的日期。文档中的示例使用年月日。

假设以下数据

year month week
2017  1     1
2017  2     35
2017  3     50

我该怎么用。 makedate() 有上面的数据吗?

使用基础 POSIXct 的潜在解决方案。

df$complete_date <- as.Date(paste(df$year, df$week, 1, sep="-"), "%Y-%U-%u")

这是否产生了预期的结果?

  year month week complete_date
1 2017     1    1 2017-01-02
2 2017     2   35 2017-08-28
3 2017     3   50 2017-12-11