Good afternoon,
I have the following problem. I need to join two sets of data that have 2 variables in common, "uor" and "month". Only 1 variable does not have values for a given month. And what I wanted was that for the months that do not have information, this particular variable, would assume the value 0 and included those missing months. Below I send a code to exemplify. The idea is to include the value 0 in the variable x for months 4, 5 and 6 of the "B".
code example
library(data.table)
uor <- c(rep("A", 8), rep("B", 5), rep("C", 8), rep("D", 8))
uor2 <- c(rep("A", 8), rep("B", 8), rep("C", 8), rep("D", 8))
mes1 <- c(1:8, 1,2,3,7,8, 1:8, 1:8)
mes2 <- rep(1:8, 4)
DT <- data.table(uor, mes1, x = rnorm(length(uor)))
DT2 <- data.table(uor2, mes2, x1 = rnorm(length(uor2)), x2 = rpois(length(uor2), 4))