Dear all,
I have a large data.table and I am simply trying to replace all zeros
with NAs in a subset of columns. So I tried first:
dt[, lapply(.SD, function(x) x := ifelse(x==0, NA, x)), .SDcols=3:30]
Error in lapply(.SD, function(x) `:=`(x, ifelse(x == 0, NA, x))) :
object '.SD' not found
Clearly that's not the right approach...
Then I tried:
for (i in names(dt)[3:30]) {
eval(parse(text=paste("dt[`", i, "`==0, `", i, "` := NA]", sep="")))
}
That worked but is rather ugly.
would you recommend any better way to avoid the eval(parse()) to
perform such simple tasks?
Thanks in advance, --Mel.
_______________________________________________
datatable-help mailing list
[email protected]
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help