I have a dataset where every two rows is part of a choice set - which will be used for discrete choice analysis in mlogit. I want to delete all rows associated with a choice set, based on the values in a column.
For example - with this simple data set, lets say I wanted to remove all the pairs where there was a yellow value in one of the rows in a pair (pairs defined here by "Set").
I am assuming there must be an easy way to say if this value = "x" , and this value of this other column matches the value of that row, remove both. I'm figuring it must be something to do with ifelse or case_when in dplyr, but its the matching value part that I'm not sure about. In excel I would use a cell reference to do a simple if_then, but not sure the best way to do that in R. Thanks!
data <- data.frame(Set = sort(rep(1:20,2)),
Choice = rep(c(T,F),20),
Color = sample(
rep(c("Red","Blue","Green","Yellow"),5)))