title: Using dplyr mutate_at with custom function
body: <p>I want to take two variables from a table and divide them by a third variable and add these computations as two new columns. The <code>mutate_at</code> gets me very close but within the custom function, <code>f</code> below, I want to access another column in the data set. Any suggestions or alternate tidy tools approaches?</p>
  <pre><code>library(dplyr)
  # this works fine but is NOT what I want
  f &lt;- function(fld){
    fld/5
  }
  
  # This IS what I want where wt is a field in the data
  f &lt;- function(fld){
    fld/wt
  }
  
  mutate_at(mtcars, .vars = vars(mpg, cyl), .funs = funs(xyz = f))
  
  # This works but is pretty clumsy
  f &lt;- function(fld, dat) fld/dat$wt
  mutate_at(mtcars, .vars = vars(mpg, cyl), .funs = funs(xyz = f(., mtcars)))
  
  # This is closer but still it would be better if the function allowed the dataset to be submitted to the function without restating the name of the dataset
  
  f &lt;- function(fld, second){
    fld/second
  }
  
  mutate_at(mtcars, .vars = vars(mpg, cyl), .funs = funs(xyz = f(., wt)))
  </code></pre>