I'm trying to replace NAs in a single column of a datatable in R with "-999" and I can quite get it.
There is related question here on Stackoverflow but I think this can be done without iterating through the table.
I have a column, column_to_check
in a datatable. The column is a factor variable and has 80K observations consisting of NA, 0, and 1. I'm trying to change the NA
to -999
so I can do further work.
The code I'm working with is this:
is.na(DT[,column_to_check,with=FALSE]) = "-999"
and
DT[is.na(column_to_check), column_to_check:="-999"]
The first line sets the entire column to NA. The second doesn't work and I know is off but I think I'm close.
Can anyone help?
Thanks.