I apologize as I'm not sure how to word this title exactly.
I have two data frames. df1 is a series of paths with columns "source" and "destination". df2 stores values associated with the destinations. Below is some sample data:
df1
| row | source | destination |
|---|---|---|
| 1 | A | B |
| 2 | C | B |
| 3 | H | F |
| 4 | G | B |
df2
| row | destination | n |
|---|---|---|
| 1 | B | 26 |
| 2 | F | 44 |
| 3 | L | 12 |
I would like to compare the two data frames and add the n column to df1 so that df1 has the correct n value for each destination. df1 should look like:
| row | source | destination | n |
|---|---|---|---|
| 1 | A | B | 26 |
| 2 | C | B | 26 |
| 3 | H | F | 44 |
| 4 | G | B | 26 |
The data that I'm actually working with is much larger, and is never the same number of rows when I run the program. The furthest I've gotten with this is using the which command to get the right values, but only each value once.
df2[ which(df2$destination %in% df1$destination), ]$n
[1] 26 44
When what I would need is the list (26,26,44,26) so I can save it to df1$n
merge(df1, df2, by = "destination")- r2evans