我想要在这两个日期之间给定工作日的日期(假设星期五):
selectedMonths <- c( "201002",
"201103"
)
如何将它们存储在data.frame中,希望的结果是:
Date
2010-02-05
2010-02-12
2010-02-19
...
2011-03-04
2011-03-11
2011-03-18
2011-03-25
我想要包含上次约会的星期五"201103
答案 0 :(得分:1)
以下是使用lubridate
和dplyr
library(lubridate)
library(dplyr)
startdates <- ymd(paste0(selectedMonths, "01"))
df <- data.frame(dates = seq(startdates[1], startdates[2], by = "day"))
df %>%
mutate(weekday = weekdays(dates)) %>%
filter(weekday == "Friday")