Merging results in an error (Error: cannot allocate vector)?

35 Views Asked by At

I have two data frames df1 and df2 like below

df1

ID
1
1
1
1
2
2
2
2

df2

ID CD
1 A
1 A
1 A
1 A
2 C
2 C
2 C
2 C

I need to join these two data frames in a way that all matching 'ID' rows in df2 are brought into df1 with the column 'CD.' The expected merged data frame should look like this:

df3

ID CD
1 A
1 A
1 A
1 A
2 C
2 C
2 C
2 C

I am trying left join in R (code below), but I end up having more rows than what is needed.

    df3 <- df1 |>
            left_join(df2, join_by(ID))
0

There are 0 best solutions below