title: How to pass a variable name and string constant as function parameters in R?
body: <p>I am new to R and have a question.
  In the function below, <code>myclusterTEST</code> and <code>price_tiers_new</code> are constants. This means every time this function is run, the variables created will always be called <code>myclusterTEST</code> and <code>price_tiers_new</code>.</p>
  
  <p>Is there a way to pass these two variables as function parameters? This way, we can generalize the function to run for any variables. </p>
  
  <pre><code>MyFunction &lt;- function(swindex,total) {
   swdist = as.dist(1/(swindex))
   fit1 &lt;- hclust(swdist, method="ward.D") 
   **myclusterTEST** &lt;- cutree(fit1, k=2) 
  
    data_clusterTEST &lt;- data.frame(**myclusterTEST**)
  
  
    # Create a new column for rownames
    d &lt;- data_clusterTEST
    names &lt;- rownames(d)
    rownames(d) &lt;- NULL
    new_data_cluster &lt;- cbind(names,d)
  
    out_total &lt;- merge(total,new_data_cluster, by.x=c("**price_tiers_new**"), by.y=c("names"))
  
    return(out_total) 
  }
  test=myFunction(swmat_clean,total)
  </code></pre>