title: R, data.table: How to assign values of some columns based on the names of other columns, which are stored in a character vector?
body: <p>I have the following data table:</p>
  
  <pre><code>dt=data.table(a=seq(1,3),b=letters[seq(1,3)],
            c=seq(4,6),d=letters[seq(4,6)])
  dt
     a b c d
  1: 1 a 4 d
  2: 2 b 5 e
  3: 3 c 6 f
  </code></pre>
  
  <p>I store the names of some columns in one vector and the names of other columns in another vector:</p>
  
  <pre><code>names1=names(dt)[1:2]
  names2=names(dt)[3:4]
  </code></pre>
  
  <p>I need to assign the values of the columns stored in names2 to the columns of names1 when some conditions apply. Something like</p>
  
  <pre><code>dt[c(2,3),names1:=names2]
  
  dt
     a b c d
  1: 1 a 4 d
  2: 5 e 5 e
  3: 6 f 6 f
  </code></pre>
  
  <p>I have tried the following syntax without success:</p>
  
  <pre><code>dt[c(2,3),names1:=dt[c(2,3),names2,with=F]]
  </code></pre>
  
  <p>But it still tries to assign the values of the string vectors contained in names2</p>