My question pertains to this post: Conditional merge/replacement in R
I am using the data.table solution referenced there. The only issue is that I need to do this as part of a loop. In essence, I just need the following code to work:
library(data.table)
df1 = data.table(x1 = c(1, 2, 3, 4, 5), x2 = c('a', 'b', 'c', 'd', 'e'))
df2 = data.table(x1 = c(1, 2, 3, 4), x2 = c('a', 'x', 'x', 'd'))
z = df1[df2, on = .(x1), x2 := i.x2] # Works perfectly
varname = 'x2'
z = df1[df2, on = .(x1), get(varname) := i.get(varname)] # Doesn't work