I read data from different sources into a data.table. Two sources supply different variables for the same time step.
How can I replace the missing variables by the other source (row)?
Here is a minimal example:
(gg = data.table(SourceCode = c(1,1,2,2), time = c(1,2,1,2), LE = c(10,10,NA,NA), R = c(NA,NA,20,30)))
SourceCode time LE R
1: 1 1 10 NA
2: 1 2 10 NA
3: 2 1 NA 20
4: 2 2 NA 30
> # rename SourceCode
> gg[SourceCode == 1, SourceCode := 2 ]
> gg
SourceCode time LE R
1: 2 1 10 NA
2: 2 2 10 NA
3: 2 1 NA 20
4: 2 2 NA 30
Desired output:
SourceCode time LE R
1: 2 1 10 20
2: 2 2 10 30