I got an R data frame and tried to find rows where, simultaneously, the entries of the column data_recalls$Attributed_Brand match and the time periods overlap. The time periods can be found in the columns Before_Date_Recall and After_Date_Recall. Possible matches would look like this:
(1) data_recalls$Attributed_Brand: Nike; Before_Date_Recall: 2018-09-22; After_Date_Recall: 2018-10-21
(2) data_recalls$Attributed_Brand: Nike; Before_Date_Recall: 2018-10-19; After_Date_Recall: 2018-10-24
Unfortunately, I can only come up with a solution where the code looks for matches in the column data_recalls$Attributed_Brand and, after that, for overlapping dates, which does not create the results needed. My data frame looks like this
data_recalls <- data.frame(Attributed_Brand = c("Nike", "Adidas", "Nike", "Puma"),
Before_Date_Recall = c("2018-09-22", "2018-09-20", "2018-10-19", "2018-11-01"),
After_Date_Recall = c("2018-10-21", "2018-10-24", "2018-10-31", "2018-11-10"),
stringsAsFactors = FALSE)
Thanks for any suggestions!
Sounds like the ivs package would work for you. The
groupscolumn allows you to identify overlapping rows within each brand name.And here is one other alternate way that may be faster depending on the structure of your actual dataset