I have two data.tables. One has some NA
values which I want to replace with the value from the same position (row / col) of the second data.table.
I can do it for each column separately. Is there a way to do all columns in one go?
Reprex:
x <- data.table(
a = runif(10),
b = runif(10)
)
x[3, a := NA]
x[7, a := NA]
x[5, b := NA]
y <- data.table(
a = runif(10)*100,
b = runif(10)*100
)
# this works but I have to go row by row
x[is.na(a), a := y[is.na(x$a), a]]
x[is.na(b), b := y[is.na(x$b), b]]