I have two datasets dat1 and dat2. I would like to pull out rows from dat1 which match the pairs of variables from dat2. var6 can be matched in any of var1, var2, var3, and var4. var7 must be matched with var5.
I would like to come up with a solution using the map functions from the purr package in tidyverse but I'm not sure where to start. Thank you for any help!
dat1 <- data.frame(id = c(1:9),
var1 = c("x","x","x","y","y","y","z","z","z"),
var2 = c("c","c","c","d","d","d","e","e","e"),
var3 = c("f","f","f","g","g","g","h","h","h"),
var4 = c("i","i","i","j","j","j","k","k","k"),
var5 = c("aa","aa","aa","aa","aa","aa","bb","bb","bb"), stringsAsFactors = FALSE)
dat2 <- data.frame(var6 = c("c", "d", "l", "m", "n"),
var7 = c("aa", "bb", "aa", "aa","aa"), stringsAsFactors = FALSE)
In this example the result would pull out rows 1, 2, and 3 from dat1 as "c" is matched in var2 and "aa" is matched in var5.