I think I need a little more information to help you with this, why a single TillSlip can have two values for Sex?
It seems a little odd and the answer might be different if this is just a mistake, but if it's not, then you can do something like this
library(tidyverse)
sample_df <- data.frame(stringsAsFactors=FALSE,
TillSlip = c(1, 1, 1, 2, 2, 3, 3, 3),
Item = c("a", "b", "c", "b", "d", "a", "c", "b"),
Sex = c(1,2,2,2,1,2,1,2),
Flag = c("yes", "yes", "yes", "no", "no", "yes", "yes", "yes")
)
sample_df %>%
group_by(TillSlip) %>%
arrange(TillSlip, Item) %>%
summarise(Item = paste(Item, collapse = " "),
Sex = paste(Sex, collapse = " ")) %>%
mutate(flag = str_detect(Item, "b.*c")) %>%
separate_rows(Item, Sex)
#> # A tibble: 8 x 4
#> TillSlip Item Sex flag
#> <dbl> <chr> <chr> <lgl>
#> 1 1 a 1 TRUE
#> 2 1 b 2 TRUE
#> 3 1 c 2 TRUE
#> 4 2 b 2 FALSE
#> 5 2 d 1 FALSE
#> 6 3 a 2 TRUE
#> 7 3 b 2 TRUE
#> 8 3 c 1 TRUE