title: What's wrong with this function (R) (Beginner)
body: <p>I'm trying to make a function that automatically performs the group_by and summarize commands of dplyr on a particular dataframe (x) that has columns of interest (y).  The code I wrote is:</p>
  <pre><code>    mysummary &lt;– function(x, y){
                       k = x %&gt;%           
                             group_by(x$y) %&gt;%
                             summarize(col.name = mean(var.name))
                       return(k)
                    }
  </code></pre>
  <p>This either doesn't work at all (saying there is no column called y if I just have y as the argument in the group_by function) or with current code above returns a tibble that is the same irrespective of what I group by (it's always grouped by the variable year in the dataset in this case, regardless of what I use as the y argument).  Can anyone help explain why this isn't working?</p>