Merging data frame

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 |

Thank you

You can use dplyr::left_join()

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

Created on 2022-06-30 by the reprex package (v2.0.1)

Note: Next time please provide a proper REPRoducible EXample (reprex) illustrating your issue.

Thanks a lot !!! it works i was missing the copy/paste friendly format for it to work, thank you

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.