I have three data frames, the first (with column headers, but no row numbering) looks like
ID 1 2 3
A 12 NA NA
B NA 7 NA
C NA NA 22
The second may look like
ID 1 2 3
A NA 6 NA
B NA NA 29
C 43 NA NA
Lastly, the third looks like
ID 1 2 3
A NA NA 32
B 5 NA NA
C NA 2 NA
The first column is an ID column and the same for all three data frames. The final three columns represent the same variables (1, 2, and 3). The record for observation A, variable 1 is only in one of the data sets. So is the record for observation A, variable 2, but it’s in a different data set.
How can I merge these data sets together to get something like
ID 1 2 3
A 12 6 32
B 5 7 29
C 43 2 22
I apologize that I didn’t have a better way of describing this problem. If someone could share the terminology for it, that would be great.
Nice title! This is quite similar to R – Vector/ Array Addition
You can turn your data into a multi-dimensional array then sum or take the mean across the “puzzle piece” dimension:
Then you’re only left with pasting the ID column back.