I have multiple data sets that I have been combining into one summary data frame in R. I am at the last step, but I am stymied.
Here is a dummy scenario: Imagine the two data frames df1 and df2 being
df1 df2
ID Make ID Max
1 A 1 2
1 B 2 3
2 A 3 5
2 B
2 B
2 C
3 B
I want to show all unique instances of "Make" for each ID and append that to df2 The resulting df2 should look like:
df2
ID Max Make
1 2 A,B
2 3 A,B,C
3 5 B
My attempts have not worked. This is the closest I have gotten:
df2[df1
, ':=' (Make = paste(Make, collapse = ","))
, by = .EACHI
, on = .(ID = ID)]
ID Max Make
1: 1 2 B
2: 2 3 C
3: 3 5 B
Any help is appreciated.