Alright so lets say we have a data frame that looks like this:
Month Product sales sales_lag YoY_change chart_color
2021-12-01 Tshirt 82525 108748 -0.2411 Negative
2022-01-01 Tshirt 109411 138472 -0.2099 Negative
2022-02-01 Tshirt 106934 115497 -0.0741 Negative
2021-12-01 Pants 97863 78419 0.2480 Positive
2022-01-01 Pants 103296 100614 0.0267 Positive
2022-02-01 Pants 82306 76913 0.0701 Positive
I'm trying to figure out a way to count the Product that has the longest run of months with negative YoY_change. So in this case, I'm looking for something that would return a table like this:
Negative_run
Tshirt 3
Pants 0
Telling us that Pants had positive YoY growth in the most recent month, but T-shirt is on a 3 Month negative streak. And while its not shown in this dataset, it would need to account for a Product being positive one month and negative the next. I'd like to do this within the tidyverse if possible, but open to other options in the R universe.
