title: Data frame column as argument to dplyr R function
body: <p>I would like to pass a column name as an argument to a function I've created that uses the dplyr package. </p>
  
  <pre><code>df = data.frame(grade = c(1,1,1,3,3,5,7,8,8,4),
                  score = c(10,20,40,43,56,29,59,37,61,88))
  
  tmp.func = function(df.name, variable.name, year.label){
  
    require("dplyr")
  
    df = df.name %&gt;%
      group_by(grade) %&gt;%
      summarise(n = n(),
                M = mean(variable.name),
                SD = sd(variable.name),
                P25 = quantile(variable.name, probs = .25),
                P50 = quantile(variable.name, probs = .50),
                P75 = quantile(variable.name, probs = .75)) %&gt;%
      mutate(grade = as.numeric(as.character(variable.name))) %&gt;%
      arrange(grade) %&gt;%
      dplyr::select(grade,
                    n,
                    M, 
                    SD,
                    P25, 
                    P50, 
                    P75)
  
    colnames(df) = paste(names(df), ".", year.label, sep = "")
  
    df
  
  }
  
  tmp = tmp.func(df.name = df, variable.name = "score", year.label = ".1718")
  
  </code></pre>
  
  <p>This code results in the below error message. I have to run this same function dozens of times so I need to create a function that can handle this. Is there a better way to approach the problem?</p>
  
  <pre><code>Error in (1 - h) * qs[i] : non-numeric argument to binary operator
  In addition: There were 12 warnings (use warnings() to see them)
  </code></pre>