I have a dataframe like this:
test1 = data.frame("id" = c("FC01", "FC01", "FC22", "FC03", "FC01"),
"product" = c("p01", "p02", "p03", "p01", "p03"),
"year" = c("2018", "2017", "2015", "2018", "2016"))
I need to find the IDs that appear more than onc, bought between 2016 and 2018, and know which products they bought and which year. Is it possible to create a new dataframe that showing the ids and how many times they appear and when did this happen? Something like this:
test2 = data.frame("times" = c(3, 1), "id" = c("FC01", "FC03"),
"year" = c("2018, 2017, 2016", "2018"))
I used dplyr
and tried to group by id and filter every id that appears more than once, but I don't know how to continue to get something like this test2. I appreciate any tips in this regard.