If I have a tibble where each row represents a component of some object and multiple components share and object, is there a way to analyze all of a given objects components and remove its corresponding rows if it doesn't match some condition?
For example, lets say I want to clean up the table below
tib <- tibble(object = c("a", "a", "a", "a", "b", "b", "b"),
component = c("x", "x", "y", "z", "x", "y", "y"),
data = 1:7)
I know an object must contain exactly one component "x" and thus object "a" is not valid because it has two. So all four rows corresponding with object "a" need to be removed.
I know that the filter() function can work on whole groups but I'm struggling to find a way to analyze the group within the filter function. The closest I think I've come is below but it doesn't work at all. Maybe I'm completely off.
tib %>%
group_by("object") %>%
filter(count(cur_data(), component)$b != 1)