title: Converting 1M to 1000000 elegantly
body: <p>I want to convert:</p>
  
  <pre><code>library(data.table)
  market.cap &lt;- data.table(cap=c("1B", "10M", "2M"))
  
    cap
  1  1B
  2 10M
  3  2M
  </code></pre>
  
  <p>to:</p>
  
  <pre><code>      cap
  1 1000000000
  2   10000000
  3    2000000
  </code></pre>
  
  <p>Here's my solution. It works, but involves adding a column, which I know isn't necessary. What's a better way? </p>
  
  <pre><code>market.cap[, cap1 := cap]
  market.cap$cap = sapply(market.cap$cap, function(x) (as.numeric(temp &lt;- gsub("B", "", x)) * 1000000000))
  market.cap$cap1 = sapply(market.cap$cap1, function(x) (as.numeric(temp &lt;- gsub("M", "", x)) * 1000000))
  M = data.frame(x = na.omit(market.cap$cap))
  B = data.frame(x = na.omit(market.cap$cap1))
  rbind(M,B)
  </code></pre>