title: In R data.table multiplication by column name based on values of another column
body: <p>I want to convert some prices in different currencies to a specific currency.
  Suppose I have this:</p>
  
  <pre><code>library(data.table)
  set.seed(100)
  DT &lt;- data.table(day=1:10, price=runif(10), currency=c("aud","eur"), 
                   aud=runif(10) + 1, eur=runif(10) + 1.5)
  DT
      day        price currency      aud      eur
   1:   1   0.30776611      aud 1.624996 2.035811
   2:   2   0.25767250      eur 1.882166 2.210804
   3:   3   0.55232243      aud 1.280354 2.038349
   4:   4   0.05638315      eur 1.398488 2.248972
   5:   5   0.46854928      aud 1.762551 1.920101
   6:   6   0.48377074      eur 1.669022 1.671420
   7:   7   0.81240262      aud 1.204612 2.270302
   8:   8   0.37032054      eur 1.357525 2.381954
   9:   9   0.54655860      aud 1.359475 2.049097
  10:  10   0.17026205      eur 1.690291 1.777724
  </code></pre>
  
  <p>The price of every day is expressed in the respective currency shown in the currency column. So 0.30776611 on first day is in AUD (Australian Dollars), and 0.25767250 in EUR (Euro). Columns <code>aud</code> and <code>eur</code> show the exchange rates of the respective currencies in dollars. How do I create a new price column expressed in dollars in a <code>data.table</code> way? </p>
  
  <p>I need to multiple <code>price</code> by the appropriate column name based on <code>currency</code> in order to obtain this:</p>
  
  <pre><code>DT
      day        price currency      aud      eur price.in.usd
   1:   1   0.30776611      aud 1.624996 2.035811    0.5001187
   2:   2   0.25767250      eur 1.882166 2.210804    0.5696634
   3:   3   0.55232243      aud 1.280354 2.038349    0.7071682
   4:   4   0.05638315      eur 1.398488 2.248972    0.1268041
   5:   5   0.46854928      aud 1.762551 1.920101    0.825842
   6:   6   0.48377074      eur 1.669022 1.671420    0.8085841
   7:   7   0.81240262      aud 1.204612 2.270302    0.9786299
   8:   8   0.37032054      eur 1.357525 2.381954    0.8820865
   9:   9   0.54655860      aud 1.359475 2.049097    0.7430328
  10:  10   0.17026205      eur 1.690291 1.777724    0.3026789
  </code></pre>
  
  <p>So for the 1st day I multiplied <code>price * aud = 0.30776611 * 1.624996</code>, because price was in <code>aud</code> in the <code>currency</code> column, while on the 2nd <code>price * eur = 0.25767250 * 2.210804</code> for the same reason.</p>
  
  <p>The real data include around 40 currencies and thus multiple <code>ifelse()</code> creating an arrow anti-pattern are not very convenient. </p>
  
  <p>For the moment, with a subsample of my data, I have this:</p>
  
  <pre><code>DT.all[, price := ifelse(curcdd=="AUD", adj.price * AUD, 
                         ifelse(curcdd=="BEF", adj.price * BEF, 
                                ifelse(curcdd=="BGN", adj.price * BGN, 
                                       ifelse(curcdd=="CHF", adj.price * CHF, 
                                              ifelse(curcdd=="CZK", adj.price * CZK, 
                                                     ifelse(curcdd=="DEM", adj.price * DEM, 
                                                            ifelse(curcdd=="EUR", adj.price * EUR, 
                                                                   ifelse(curcdd=="FRF", adj.price * FRF, 
                                                                          ifelse(curcdd=="GBP", adj.price * GBP, 
                                                                                 ifelse(curcdd=="ILS", adj.price * ILS, 
                                                                                        ifelse(curcdd=="JPY", adj.price * JPY, 
                                                                                               ifelse(curcdd=="NLG", adj.price * NLG, 
                                                                                                      ifelse(curcdd=="NOK", adj.price * NOK, 
                                                                                                             ifelse(curcdd=="PLN", adj.price * PLN, 
                                                                                                                    ifelse(curcdd=="SEK", adj.price * SEK,
                                                                                                                           ifelse(curcdd=="SGD", adj.price * SGD,
                                                                                                                                  ifelse(curcdd=="USD", adj.price, NA)))))))))))))))))]
  </code></pre>
  
  <p>which works, but it's only about 20 currencies, and doing all of them (~40) is certainly not elegant...</p>
  
  <p>Thank you very much!</p>