newdata <- data.frame(
id = c(
1202L, 1202L, 1202L, 1202L, 1202L, 1202L,
1202L, 1202L, 1202L, 1202L, 1202L, 1202L, 1202L, 1202L, 1202L,
1202L, 1202L
),
bill.date = as.factor(c(
"2011-01-01",
"2011-02-01", "2011-03-04", "2011-04-03", "2011-05-02",
"2011-06-01", "2011-07-01", "2011-07-31", "2011-08-30",
"2011-09-30", "2011-10-29", "2011-11-29", "2013-02-01",
"2013-03-03", "2013-04-01", "2013-04-30",
"2013-06-02"
))
)
library(tidyverse)
library(lubridate)
newdata <- mutate(newdata, month = month(bill.date))
newdata <- mutate(newdata, year = year(bill.date))
ids_with_12_in_2011 <- filter(
newdata,
year == 2011
) %>%
group_by(id) %>%
count() %>%
filter(n == 12) %>%
select(id)
ids_with_12_in_2011_with_data <- left_join(
ids_with_12_in_2011,
newdata
)