title: R - Undefined columns selected when subsetting data frame inside a function
body: <p>Hi I have a data frame called "outcome" with a column called "pneumonia" and some other column like "State" and "Hospital.Name"</p>
  
  <p>when I run in the command line</p>
  
  <pre class="lang-r prettyprint-override"><code>outcome &lt;- read.csv("Assigment3/outcome-of-care-measures.csv", colClasses = "character")
  temp &lt;- subset(outcome, State =="NY", select=c(Hospital.Name, Pneumonia)
  </code></pre>
  
  <p>it works and it creates the temp data frame with 2 columns the Hospital.Name and Pneumonia.</p>
  
  <p>but when I create a function that contains the same instruction</p>
  
  <p>state is a value inside the state column, and outcome1 is just the column name</p>
  
  <pre class="lang-r prettyprint-override"><code>best &lt;- function(state, outcome1) {
      outcome &lt;- read.csv("Assigment3/outcome-of-care-measures.csv", colClasses = "character")  
      temp &lt;- subset(outcome, State ==state, select=c(Hospital.Name, outcome1))
  }
  </code></pre>
  
  <p>and I call the function:</p>
  
  <pre><code>best("NY","Pneumonia")
  </code></pre>
  
  <p>I get the error:  </p>
  
  <blockquote>
    <p>Error in [.data.frame`(x, r, vars, drop = drop) :
            undefined columns selected</p>
  </blockquote>
  
  <p>I know the problem is with the <code>outcome1</code> variable, since when if I hardcode <code>outcome1</code> in the above function, instead of passing it in as an argument, the function works as expected.</p>