【发布时间】:2021-11-12 23:48:03
【问题描述】:
这是我的示例数据,我想在 wday 函数中从 lubridate 包自定义 week_start
mydate <- data.frame(Date = c("13/09/2021", "13/09/2020", "13/09/2019", "13/09/2018"))
例如,一周的开始是year %% 7。但是当我运行我的代码时出现以下错误
numerical expression has 4 elements: only the first used
library(lubridate)
library(dplyr)
mydate2 <- mydate %>%
mutate(Date = ymd(as.Date(as.factor(Date), format = "%d/%m/%Y")),
years = year(Date),
days = wday(Date, label = TRUE, week_start = years %% 7))
我想我需要使用purrr 中的map 函数。试了几次,还是不行。
非常感谢。
【问题讨论】: