I am quite new to R and never worked with any bigger data. For the examples i reduced the two dataframes:
df1
| id | val1 | val2 |
|---|---|---|
| 11 | 1 | 2 |
| 11 | 2 | 5 |
| 22 | 2 | 2 |
| 22 | 4 | 6 |
| ... | ... | ... |
df2
| id | val1 | val2 |
|---|---|---|
| 11 | 5 | 3 |
| 22 | 6 | 5 |
| ... | ... | ... |
I am looking for a way to add the values of df2 to each value in df1 with the same id.
So the result should be something like this:
| id | val1 | val2 |
|---|---|---|
| 11 | 6 | 5 |
| 11 | 7 | 8 |
| 22 | 8 | 7 |
| 22 | 10 | 11 |
| ... | ... | ... |
Because the original data is over 3000 observations of 47 variables with 8 different id I am looking for a solution where the values are not added one by one.
#reproducible data
df1 <- read.table(text = "id val1 val2
11 1 2
11 2 5
22 2 2
22 4 6", header = TRUE)
df2 <- read.table(text = "id val1 val2
11 5 3
22 6 5", header = TRUE)