I want to assign values to a data.table column, but I need to use a variable to represent the column name. I actually want to assign multiple values to specific rows, but my problem is using the variable. Using get() doesn't work.
var1 <- "Ozone"
airq<-as.data.table(airquality)
fillwith <- as.data.table(data.frame(res=sample(1:100,37,replace=T)))
airq[is.na(get(var1)),get(var1):=fillwith[,res]] # doesn't work
>Error in get(var1) : object 'Ozone' not found
airq[is.na(get(var1)),Ozone:=fillwith[,res]] # works
With=FALSE won't of course work for assignment by reference.
Thank you in advance.