Re:Joins In Steps
by wodenokoto on Saturday May 11, 2019 @12:34PM
(#19886989)
I tend to do like
x %>% left_join(y %>% preprocess1() %>% preprocess2())
But yes, my understanding is that right and left joins are the exact same function, just with the order of input switched.
Think of left join as a join from x to y, and a right join as a join from y to x, where x is the data we keep all of and y is the data we keep only when there's a match.
Then, in R, I often use right joins when my "y" data requires preprocessing, resulting in lines of code that are like: (y %>% preprocess1() %>% preprocess2() %>% right_join(x)). I could of course write this as "y_preprocessed = y %>% preprocess1() %>% ...; x %>% left_join(y_preprocessed)" but I think the former is actually a little syntactically clearer.