我想要一个计算每月特定天数的函数..
IE。13 年 11 月 -> 5 个星期五.. 而 13 年 12 月将返回 4 个星期五..
是否有一个优雅的函数可以返回这个?
library(lubridate)
num_days <- function(date){
x <- as.Date(date)
start = floor_date(x, "month")
count = days_in_month(x)
d = wday(start)
sol = ifelse(d > 4, 5, 4) #estimate that is the first day of the month is after Thu or Fri then the week will have 5 Fridays
sol
}
num_days("2013-08-01")
num_days(today())
有什么更好的方法来做到这一点?