title: Creating a function with multiple arguments using dplyr
body: <p>I am struggling with using <code>dplyr</code>functions in own functions. I am closer to understand but still missing full understanding.
  Here I have <code>df</code> containing <code>type</code> and <code>D10</code> variables.</p>
  
  <pre><code>df &lt;- data.frame(type = c("KL", "KL", "A", "A", "B", "B", "9999", "-1"), 
                   D10 = rnorm(8, 3, 4))
  </code></pre>
  
  <p>I want to write a function that in a new column will return <code>M</code> if the <code>type == "KL"</code>; <code>"-1"</code> if the <code>type %in% c(9999, -1)</code> and that will return <code>K</code> for all the other cases. I want the values of <code>9999, -1, KL</code> to be possible to change when the function is initiated. </p>
  
  <p>My tries i ended with the function that look like this:</p>
  
  <pre><code>klme &lt;- function(dat, met, minusy = c(-1, 9999), Sortnr, type){
    mutate_call &lt;- lazyeval::interp(~ifelse(a %in% met, "M", ifelse(a %in% minusy, "-1", "K")), a = as.name(Sortnr))
    dat %&gt;% mutate_(.dots = setNames(list(mutate_call), type))
  }
  
  klme(df, c("KL"), minusy = c(-1, 9999), "Sortnr", "typ")
  </code></pre>
  
  <p>that return only <code>K</code> in the <code>typ</code> column while I'd like to obtain output like this:</p>
  
  <pre><code>  type        D10 type.1
  1   KL -5.3210620      M
  2   KL  4.4832414      M
  3    A -5.3979886      K
  4    A  2.7933964      K
  5    B -0.9602293      K
  6    B  4.5097305      K
  7 9999 -3.9650796     -1
  8   -1  5.2700609     -1
  </code></pre>