title: Setting column contents as variable in function (R)
body: <p>I'm trying to create a table in R that calculates summary statistics based on a group (&quot;Treatment&quot;) as part of a longer function. Before running the function I'm inputting the dataframe name (data) and column (y) I want summarized.</p>
  <pre><code>data = df
  y = df$columna
  
      x &lt;- function(model) {
      summary &lt;- data %&gt;% 
      group_by(Treatment) %&gt;% 
      summarize(Mean= mean(y), StdError = se(y), Mean_StdError = mean(y) + se(y), Max= max(y), Min= min(y), 
      Range = max(y)-min(y),   n = n()) }
  </code></pre>
  <p>However, it seems that because y is saved as a new variable that is not associated with the dataframe, R is calculating summary statistics for the whole data set rather than grouping by treatment. How can I set up my code so that I can designate which column I want (y) as a variable outside of the function, instead of replacing y with df$columna? I want to set it up so I can easily run the function on a variety of different columns and dataframes. I'm guessing I need to reference the column differently? Thanks!</p>