I'm having a problem with filling in a column in my data frame.
I've got two data frames. DF.A is my main data frame that already has some other measurements, which results in some Variables showing up multiple times per ID. Then there is DF.B that has measurements for almost every variable for each ID.
DF.A<- data.frame(Id=c("001","001","001","002","002","003","003","003"),
Variable=c("0_1","2_1","2_1","0_1","0_2","0_1","0_1","2_1"),
Measurement=c(NA,NA,NA,NA,NA,NA,NA,NA))
DF.B<- data.frame(Id=c("001","002","002","003","003"),
Variable=c("2_1","0_1","0_2","0_1","2_1"),
Measurement=c(1,2,3,4,5))
What I want to have is DF.A but with the measurement filled in if the ID and Variable match like so:
DF.C<- data.frame(Id=c("001","001","001","002","002","003","003","003"),
Variable=c("0_1","2_1","2_1","0_1","0_2","0_1","0_1","2_1"),
Measurement=c(NA,1,1,2,3,4,4,5))
I was looking into match and paste statements, but then it would just insert the measurement of row 12 in DF.B if row 12 of DF.A had any match in DF.B.
Anyone know how I get the measurement from the match in DF.B to show up at that same match in DF.A?