I am trying to join two data.tables in R. I am joining them by name and I would like to "insert" rows from one data table into the name groups of another.
So for example: Data table A has "names" and "amounts", data table B has "names" and "addresses" (but more than one address per name). I would like a data table which has each name, the corresponding addresses, and a single "amount" for each group of names.
I tried using "left_join" in dplyr, but the amount column would get duplicated for each "address" row.
Anyone have any ideas? Thank you.
Example Picture (joining table 1 and 2 to create 3):
or even like this:
EDIT: Added a reproducible example of what the two data sets are like and what the desired output is
table_one <- data.frame(name=c("x","y","z"), amount=c("$100","200","300"))
table_two <- data.frame(name=c("x","x","y","z","z","z"), address=c("A","B","C","D","E","F"))
output <- data.frame(name=c("x","x","y","z","z","z"),
address=c("A","B","C","D","E","F"), amount=c("$100","","$200","$300","",""))