title: Vectorise assignment of R data.table cells with column differing by row
body: <p>I'm having a problem thinking about how to efficiently assign individual cells of a data.table by reference. Each column (aside from id) is indicative of that subjects state on a particular day.</p>
  
  <p>For the sake of illustration, the column to be toggled of each row is stored in a separate list or vector. The following for loop does the job, but the actual data are very large (hence also assigning by reference), and a more native solution would be ideal.</p>
  
  <pre><code>dt = data.table(id = letters[1:5],
                  `1`=0,`2`=0,`3`=0)
  
  d = c(3,2,1,2,3)
  
  for (i in 1:nrow(dt)) {
    print(d[i])
    dt[i,1+d[i] := 1]
  }
  
  print(dt)
  # id 1 2 3
  # 1:  a 0 0 1
  # 2:  b 0 1 0
  # 3:  c 1 0 0
  # 4:  d 0 1 0
  # 5:  e 0 0 1
  </code></pre>
  
  <p>Everything I try using .SD or .I fails, perhaps someone could point me in the right direction?</p>
  
  <p>e.g.</p>
  
  <pre><code>dt[,d[.I] := 1]
  </code></pre>