How would you solve the following problem in R / tidyverse?:
sample data:
tibble(
date = seq(as.Date(paste0("2010-01-",runif(1,1,25))), by = "month", length.out = 24),
machine_ID = sample(letters[1:10],size = 24,replace = T),
machine_cat = rep(c(1,2),12)
)
objective:
Add a column called last6m
, which counts the number of unique machine_ID
s observed in the last 6 months, within the associated machine_cat
.
tidyverse and no looping is prefered (purrr is ok).
Appriciate if anyone would take a quick look! Thanks in advance :-)