我想在data.table
的每一列中将0
替换为NA
。
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
我试过这个
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.
并且我也尝试了这个
dt1[dt1==0, .SD :=NA]
编辑过
部分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