I'm currently working on incorporating elements of one data table with another "master" set, by some reference column. To make things clearer, I have created some sample data:
This is the dataset I am looking to join onto another "master set".
data.frame(refID = c(1,3,4,5,7,8), value = c(3.3,3.9,4.4,8.0,1.1,2.5))
refID value
1 3.3
3 3.9
4 4.4
5 8.0
7 1.1
8 2.5
The master set:
data.frame(refID = 1:9, value = rep(0,9))
refID value
1 0
2 0
3 0
4 0
5 0
6 0
7 0
8 0
9 0
I am basically looking to send the column of values from the first data set into the second, but where there are gaps, let them have a value of 0. Ultimately, I am hoping to get:
Resulting Set:
refID value
1 3.3
2 0.0
3 3.9
4 4.4
5 8.0
6 0.0
7 1.1
8 2.5
9 0.0
I've played around with some stuff in the dplyr
and data.table
packages but can't seem to really pinpoint a good and direct way of doing it. Advice would be greatly appreciated, many thanks.