Hi everyone, thank you for taking the time
I have two data frame that i wish to merge in a specific way
If we simplify stuff it would look like that :
df1 :
A | B
a | 23
b | 10
c | 8
d | 43
e | 29
df2 :
A' | C
a | 4
c | 9
d | 18
I'm looking to have a data frame with
df3 :
A | B | C
a | 23 | 4
b | 10 |
c | 8 | 9
d | 43 | 18
e | 29 |
library(dplyr)
# Sample data in a copy/paste friendly format,
# replace this with your own data frames
df1 <- data.frame(
stringsAsFactors = FALSE,
A = c("a", "b", "c", "d", "e"),
B = c(23, 10, 8, 43, 29)
)
df2 <- data.frame(
stringsAsFactors = FALSE,
check.names = FALSE,
`A'` = c("a", "c", "d"),
C = c(4, 9, 18)
)
# Relevant code
df1 %>%
left_join(df2, by = c("A" = "A'"))
#> A B C
#> 1 a 23 4
#> 2 b 10 NA
#> 3 c 8 9
#> 4 d 43 18
#> 5 e 29 NA