If you have an R data.table that has missing values, how do you replace all of them with say, the value 0? E.g.
aa = data.table(V1=1:10,V2=c(1,2,2,3,3,3,4,4,
I would make use of data.table and lapply, namely:
data.table
lapply
tt[,lapply(.SD,function(kkk) ifelse(is.na(kkk),-666,kkk)),.SDcols=names(tt)]
yielding in:
V1 X V2 1: 1 -666 1 2: 2 -666 2 3: 3 a 2 4: 4 b 3 5: 5 c 3 6: 6 d 3 7: 7 -666 4 8: 8 -666 4 9: 9 -666 4 10: 10 -666 4