5
Good afternoon,
i have the following problem. I need to put together two datasets that have 2 variables in common, "uor" and "mes". Only 1 variable has no values for a given month. And what I wanted was that for the months that have no information, this particular variable, assumed the value 0 and included those missing months. Below I send a code to exemplify. The idea is to include the value 0 in variable x for months 4, 5 and 6 of uor "B".
example of code
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))