0

I have two tables that I would like to merge them based on 'Group' column but they have different rows. I have tried merge () but I got NA for rows.

A:

Group   value

A        10
A         5
A         7
B         8
B         9
B         3
B         2
B         1
B         1
C         6
C         0
C         8

B:

Group   list   code

A        1     5
B        2     3
C        1     8

desire output:

Group   value   list   cod

A        10       1     5
A         5       1     5
A         7       1     5
B         8       2     3
B         9       2     3
B         3       2     3
B         2       2     3
B         1       2     3
B         1       2     3
C         6       1     8
C         0       1     8
C         8       1     8
star
  • 743
  • 1
  • 7
  • 19

1 Answers1

1

We can ues left_join

library(dplyr)
left_join(df1, df2, by = "Group")

Or with merge from base R

merge(df1, df2, by = 'Group', all.x = TRUE)
akrun
  • 874,273
  • 37
  • 540
  • 662