<div dir="ltr">Dear list<div><br></div><div>I'm trying to access values within a data.table column by matching to elements in a vector and replacing with corresponding elements in a second vector. But I want to loop through specific column names also stored as a character vector.</div>

<div>So something like:</div><div><br></div><div>DT<span></span> <- data.table(A=seq(1:10),B=seq(1:10),C=seq(1:10))</div><div><br></div>cnm <- c("A", "B", "C")<br><div>before <- c(4, 5, 6)</div>
<div>after <- c(3, 7, 8)</div><div>
<br></div>nm <- cnm[i]<div>bfr <- before[i]</div><div>afr <- after[i]<br><div><br></div><div>DT[nm==bfr, nm:=afr]</div></div><div><br></div><div>I'm sure this is completely wrong because it didn't work.</div>

<div>So does anyone know how to correctly do this data.table solution?</div><div><br></div><div>Many thanks,</div><div>Manabu</div>
</div>