I want to replace 0
by NA
in each column of a data.table
.
library(data.table)
dt1 <- data.table(V1=0:2, V2=2:0)
dt1
V1 V2
1: 0 2
2: 1 1
3: 2 0
dt1==0
V1 V2
[1,] TRUE FALSE
[2,] FALSE FALSE
[3,] FALSE TRUE
I tried this one
dt1[dt1==0]
Error in `[.data.table`(dt1, dt1 == 0) :
i is invalid type (matrix). Perhaps in future a 2 column matrix could return a list of elements of DT (in the spirit of A[B] in FAQ 2.14). Please let datatable-help know if you'd like this, or add your comments to FR #1611.
And also tried this one
dt1[dt1==0, .SD :=NA]
Edited
Partial sessionInfo()
R version 3.2.1 (2015-06-18)
Platform: i686-pc-linux-gnu (32-bit)
Running under: Ubuntu 14.04.2 LTS
data.table_1.9.4