I am writing a function which will impute zero if a value in a column is NA. The tables I will need to impute will be in a format of:
tab = data.table(V1 = 1, var = NA, perc = NA)
Tables will have different column names but the one to impute will always be the second one. To simplify, the function could be:
impute = function(DT, variable) {
DT[is.na(get(variable)), variable := 0]
}
That second 'variable' needs to be wrapped in something to work I assume. I would like to point it to the
variable = colnames(tab)[2]
Can anyone help please