I need to know the first business day of a given month, is there some package in R containing a relevant function?
The timeDate package has a function isBizday that will help you here. There will be more elegant ways to convert the dateTime object to other formats, but this should at least get you started.
library(timeDate)
## Example data
dates <- as.Date("2013-01-01") + 0:364
Dates <- as.timeDate(dates)
## Extract the first business day of each month
bizDates <- dates[isBizday(Dates, holidays=holidayLONDON())]
firsts <- tapply(bizDates, months(bizDates), min)
sapply(firsts, function(X) as.character(as.Date(X)))
# 1 2 3 4 5 6
# "2013-01-02" "2013-02-01" "2013-03-01" "2013-04-01" "2013-05-01" "2013-06-03"
# 7 8 9 10 11 12
# "2013-07-01" "2013-08-01" "2013-09-03" "2013-10-01" "2013-11-01" "2013-12-02"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With