title: Mutate multiple columns in a dataframe
body: <p>I have a data set that looks like this.</p>
  
  <pre><code>bankname    bankid  year    totass  cash    bond    loans
  Bank A      1       1881    244789  7250    20218   29513
  Bank B      2       1881    195755  10243   185151  2800
  Bank C      3       1881    107736  13357   177612  NA
  Bank D      4       1881    170600  35000   20000   5000
  Bank E      5       1881    3200000 351266  314012  NA
  </code></pre>
  
  <p>and I want to compute some ratios based on bank balance sheets. and I want the dataset to look like this</p>
  
  <pre><code>bankname    bankid  year    totass  cash    bond    loans   CashtoAsset BondtoAsset LoanstoAsset
  Bank A      1       1881    2447890 7250    202100  951300  0.002   0.082   0.388
  Bank B      2       1881    195755  10243   185151  2800    0.052   0.945   0.014
  Bank C      3       1881    107736  13357   177612  NA  0.123   1.648585431 NA
  Bank D      4       1881    170600  35000   20000   5000    0.205   0.117   0.029
  Bank E      5       1881    32000000    351266  314012  NA  0.0109  0.009   NA
  </code></pre>
  
  <p>Here is the code to replicate the data</p>
  
  <pre><code>bankname &lt;- c("Bank A","Bank B","Bank C","Bank D","Bank E")
  bankid &lt;- c( 1, 2,  3,  4,  5)
  year&lt;- c( 1881, 1881,   1881,   1881,   1881)
  totass  &lt;- c(244789,    195755, 107736, 170600, 32000000)
  cash&lt;-c(7250,10243,13357,35000,351266)
  bond&lt;-c(20218,185151,177612,20000,314012)
  loans&lt;-c(29513,2800,NA,5000,NA)
  bankdata&lt;-data.frame(bankname, bankid,year,totass, cash, bond, loans)
  </code></pre>
  
  <p>First, I got rid of NAs in balance sheets.</p>
  
  <pre><code>cols &lt;- c("totass", "cash", "bond", "loans")
  bankdata[cols][is.na(bankdata[cols])] &lt;- 0
  </code></pre>
  
  <p>Then I compute ratios</p>
  
  <pre><code>library(dplyr)
  bankdata&lt;-mutate(bankdata,CashtoAsset = cash/totass)
  bankdata&lt;-mutate(bankdata,BondtoAsset = bond/totass)
  bankdata&lt;-mutate(bankdata,loanstoAsset =loans/totass)
  </code></pre>
  
  <p>But, instead of computing all these ratios line by line, I want to create a look to do this all at once. In Stata, I would do</p>
  
  <pre><code>foreach x of varlist cash bond loans {
  by bankid: gen `x'toAsset = `x'/ totass
  }
  </code></pre>
  
  <p>How would I do this?</p>