Re: [R] Exclude holidays in a subset of dates?

From: Diethelm Wuertz <wuertz_at_itp.phys.ethz.ch>
Date: Wed, 19 Nov 2008 21:07:37 +0100

Gabor Grothendieck wrote:

There are the timeDate and timeSeries packages with very powerful possibilities to handle weekdays, weekends and public holidays for the G7 countries and CH. You can create your own holiday calenders for many countries including fix and moveable holidays.

Note, this allows you to create very simply operators like "add two business days to a date" taking care of weekends und public as well ecclestiastical holidays all over the world!

Have look and if you like try it

Diethelm

> chron has some facilities for this that also work with "Date" class:
>
> library(chron)
> startDate <- as.Date("2008-08-15")
> endDate <- as.Date("2008-09-15")
> AllDays <- seq(startDate, endDate, by="day")
> Holidays <- as.chron(as.Date("2008-09-01"))
> is.workday <- !is.holiday(AllDays, Holidays) & !is.weekend(AllDays)
> data.frame(AllDays, is.workday)
>
>
> On Wed, Nov 19, 2008 at 1:54 PM, Brigid Mooney <bkmooney_at_gmail.com> wrote:
>
>> Hi All,
>>
>> I am iterating through dated materials, with variable start and end dates,
>> and would like to skip procedures everytime I encounter a weekend or
>> holiday. To do this, I thought the easiest way would be to create a
>> TRUE/FALSE vector corresponding to each day where it is TRUE if a workday,
>> and FALSE if a weekend or holiday.
>>
>> So far I have been able to do this for weekdays:
>>
>> startDate <- as.Date("2008-08-15")
>> endDate <- as.Date("2008-09-15")
>>
>> AllDays <- seq(startDate, endDate, by="day")
>>
>> WorkDays <- ifelse(as.numeric(format(startDate+days-1, "%w"))%%6==0, FALSE,
>> TRUE)
>>
>> But I'm a bit lost as to what to do for the holidays, for example
>> "2008-09-01" is Labor Day in the above range.
>>
>> Is there some procedure to say if an object is "in" a given list or set?
>>
>> Mathematically, I would want to test: day \in Holidays
>> where day is a given day, and Holidays is a set of all Holidays.
>>
>> Is there a way to do this without iteration since my start/endDates are
>> variable?
>>
>> Or maybe there's a very elegant solution that I don't know about as I am
>> still new to R.
>>
>> Thanks for all your help!
>>
>> [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help_at_r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Wed 19 Nov 2008 - 20:12:09 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 19 Nov 2008 - 20:30:26 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive