title: how do I pass a variable name to an argument in a function
body: <p>I am a new user to <code>R</code> and I want to recall a block of code for different variables and I want to do something like this:</p>
  <pre><code>   myfunc&lt;- function(dat, groupvar, interestvar){
        a&lt;- dat%&gt;% group_by(groupvar) %&gt;% summarize(m=mean(interestvar))
           ..... other codes ....
        return(a)   }
  
  myfunc(data=newdata, groupvar=variable1, interestvar=variable3)
  myfunc(data=newdata, groupvar=variable2, interestvar=varaible4)
  </code></pre>
  <p>Here the <code>variable1-vari</code> all are variables inside <code>newdata</code>. It seems if I call <code>intrestvar=newdata$varaible3</code>, that part will work. However, the way I call <code>groupvar</code> still don't tell the function the group by is done by <code>variable1</code>. How do I make it work?</p>