Ravi
Ravi

Reputation: 622

Subset data between specific months over multiple years

I have a issue_date column in df dataframe denoting day level data.

Based on input of year (y) and months (m), lets say 2020, 2019 & 2018 and April & June. I want to subset the data, between April and June for all years (2018,19,20).

 issue_date
1 2019-04-15
2 2019-04-15
3 2019-04-16
4 2019-04-16
5 2019-04-18
6 2019-04-23

How do I achieve this?

Upvotes: 0

Views: 496

Answers (1)

s__
s__

Reputation: 9525

Something like these could help:

library(lubridate)
library(dplyr)

df %>% filter(month(ymd(issue_date)) %in% c(4:6))

Upvotes: 2

Related Questions