[R] Exclude holidays in a subset of dates?

hadley wickham h.wickham at gmail.com
Wed Nov 19 20:14:36 CET 2008


On Wed, Nov 19, 2008 at 12: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?

Have a look at ?"%in%"

Hadley

-- 
http://had.co.nz/



More information about the R-help mailing list