I have two data frames which share same keys, and I can join them using left_join
or other join functions to merge data frames. But I have same variable in both data frames and they are missing differently. Here is my example:
df1 <- data.frame(key1= c("A", "B" , "C", "D", "E","F", "G" , "H", "I", "J"),
key2 = c("a", "b", "c", "d", "e","f", "g", "h", "i", "j"),
foo = c(NA, NA, 21 , 25,21,22, NA, 23 , 25, NA))
df2 <- data.frame(key1= c("F", "G" , "A", "B", "J"),
key2 = c("f", "g", "a", "b", "j"),
foo = c(NA, NA, 21 , 25,21))
When I call left_join(df1, df2)
it give me following data frame
key1 key2 foo
1 A a NA
2 B b NA
3 C c 21
4 D d 25
5 E e 21
6 F f 22
7 G g NA
8 H h 23
9 I i 25
10 J j NA
As you can see, I have "A a" key pair that is missing, but df2 has observation with "A a" key pair and it is not missing. How can I join this in a right way?