check to see occurrence of string with group_by

data %>% 
group_by(animal, location) %>%
mutate(more_than_one_green = any(color == "Green") > 1)

hi my goal is to see whether for any animal + location combination, whether there is more than one which is the color green. is my code above the right approach thank u!

I would something like:

data %>%
  count(animal, location, colour) %>%
  filter(colour == "green" & n > 1)
2 Likes

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.