I am hoping to perform a nested left_join and I am finding myself stuck. My goal is to construct pairwise comparisons within each household in my data, for each participant to each other participant. I am measuring variation within each participant, so each 'POS' has many additional attributes that I don't include here. I'm hoping to find a way to use a nested left_join by 'POS', so that I can directly compare each participant to each other participant, without losing any observation information from the first participant, if there is no corresponding 'POS' in the pair.
df <- tibble(house = c('a','a','a','a','b','b'), participant = c(1,1,2,2,1,2), POS = c(1,2,2,3,1,2))
df
outcome <- tibble(house = c('a','a','a','a','b','b'), participant.x = c(1,1,2,2,1,2), POS.x = c(1,2,2,3,1,2), participant.y = c(2,2,1,1,2,1), POS.y = c(NA,2,2,NA,NA,NA))
outcome
My goal is to group by houses, so that the participants are only compared who live in the same household, resulting in an output as shown below. Any suggestions would be fantastic. A nest(), then left_join() does not work because the left_join does not iterate over each possible participant. Thank you in advance!