Filter to Month-Day Interval

Viewed 1523

I have a data frame with daily observations across years. I would like to filter to a range, such as "March 10 to May 12" every year. Perhaps it's my poor googling skills, but I couldn't find some sort of month-day construction.

Here's a sample df:

set.seed(123)

dates <- seq.Date(from=as.Date("1970-01-01"), to=as.Date("2007-08-31"), by="days")

sample.df <- data.frame(date=dates, 
                        data=rnorm(length(dates)))

Another addition to complicate is to keep a range that crosses over years, such as "December 10 to February 2." It can be assumed all needed dates are contained within the dataframe, but might need to make some NA such as when the dataframe goes to 2007, so we cannot do December 10, 2007 to February 2, 2008.

2 Answers
Related