In column A, there are two factors, male and female. In column B, there are 5 assets, a to e.
df <- data.frame(ID = c(1:7),
gender = c("male","male", "male", "female", "female","female","female"),
assets = c("a,e","a,b,e,d", "b,c,e","b,c,e", "a,b,e,d", "c,d","a,d"))
How do I retrieve data where both male and female shared the same asset combinations?
I've zero clue how to write the R syntax for it and below is what I have tried
sameassets <- df %>% filter(filter(gender="male",assets) == filter(gender="female",assets))
desired output
sameassests <- data.frame(ID = c(2,5,3,4),
gender = c("male", "female", "male", "female"),
assets = c("a,b,e,d", "a,b,e,d", "b,c,e","b,c,e"))
Can someone help please?
Edit to include additional question. I also want to find out which asset combination that male does not share with female.
So the desired output for this will look like
diffassests <- data.frame(ID = c(1,6,7),
gender = c("male", "female", "female"),
assets = c("a,e", "c,d", "a,d"))