I have two data frames with string values:
df1 <- data.frame(values = c("apples_x", "oranges_z", "bananas_y", "berries_u", "melons_r"))
df2 = data.frame(values = c('apples','oranges','z','pears','x','bananas','plums','y','h','grapes','q'))
I would like to perform a pairwise comparison between both data frames, by iterating over every row of data frame 2 and assigning pair numbers where both fruit and letter of df1 value appears in df2. I want to create a new data frame that stores the pair numbers for the matches found. Ideally it would look something like this:
df3 %>% head()
values paired
<ch> <int>
1 apples 1
2 x 1
3 oranges 2
4 z 2
5 bananas 3
6 y 3
I tried to separate the values in df1 into two strings, but I am getting back strings with matches on any character.
lapply(df2, FUN=function(x){any(df1==x[[1]] & df1==x[[2]])})