title: creating a new data.table column from values of another column and a vector
body: <p>I wanna create a new data.table column by taking the value from one column and adding it to a constant that depends on the value of another column. Here is an example:</p>
  <pre><code>&quot;position_on_chrom&quot;  &quot;chromosome&quot;
  ---------------------------------
  &quot;56386845&quot;           &quot;chr3&quot;
   ...
  </code></pre>
  <p>Now I want to create a new column &quot;real_position_in_genome&quot;, where I want to add &quot;position_on_chrom&quot; to the starting position of the chromosome.</p>
  <p>I have the starting positions in a list <code>chromstart</code>. The names of the list are the chromosomes and the values are the starting position. What I tried was:</p>
  <pre><code>dt[, real_pos := as.numeric(position_on_chrom) + as.numeric(..chromstart[[chromosome]])]
  </code></pre>
  <p>When I execute this, I get (tranlated from German, so I guess it's not the exact error message)</p>
  <pre><code>Error in ..chromstart[[chr]] : 
  Attempt to choose more then one element from vectorIndex
  </code></pre>
  <p>How do I do this?
  Thanks :)</p>
  <p>EDIT:
  Here is a little example code with some more understandable variable names. I want to create a new column where I add the position to the starting position of the container to be able to plot them on a continuous x axis:</p>
  <pre><code>library(data.table)
  
  items &lt;- c(&quot;Item1&quot;, &quot;Item2&quot;, &quot;Item3&quot;, &quot;Item4&quot;)
  positions &lt;- c(&quot;1234&quot;, &quot;2345&quot;, &quot;1234&quot;, &quot;1652&quot;)
  container &lt;- c(&quot;con1&quot;, &quot;con2&quot;, &quot;con2&quot;, &quot;con3&quot;)
  
  dt &lt;- data.table(&quot;Item&quot; &lt;- items,
                   &quot;Position&quot; = positions,
                   &quot;Container&quot; = container)
  
  containerlist &lt;- c(&quot;con1&quot;, &quot;con2&quot;, &quot;con3&quot;)
  starting_position &lt;- c(&quot;0&quot;, &quot;200&quot;, &quot;500&quot;)
  names(starting_position) &lt;- containerlist
  
  dt[, total_position := as.numeric(Position) +
       as.numeric(..starting_position[[Container]])]
  </code></pre>