SyntaxFix
Write A Post
Hire A Developer
Questions
Starting from the data.table y, you can just write: y[, (cols):=lapply(.SD, function(i){i[is.na(i)] <- 0; i}), .SDcols = cols] Don't forget to library(data.table) before creating y and running this command.
y[, (cols):=lapply(.SD, function(i){i[is.na(i)] <- 0; i}), .SDcols = cols]
library(data.table)
y