title: argument is not numeric or logical: returning NA in R
body: <p>I am trying to write a function to calculate the mean of a column. The function has the arguments directory and column_name. However, I keep getting the error "argument is not numeric or logical: returning NA":</p>
  
  <pre><code>pollutantmean &lt;- function(directory, pollutant) {
  
      directoryVal &lt;- directory
      pollutantVal &lt;- pollutant
  
      pollutantData &lt;- read.csv(directoryVal)
      meanVal &lt;- mean(pollutantData$pollutantVal, na.rm = TRUE)
  
  }
  </code></pre>
  
  <p>I called it by:</p>
  
  <pre><code>pollutantmean("001.csv", "nitrate")
  </code></pre>
  
  <p>"nitrate" is one of the column names.</p>
  
  <p>Note that the following works, so I'm not sure why it's not working in my function:</p>
  
  <pre><code>mydata &lt;- read.csv("001.csv")
  mean(mydata$nitrate, na.rm = TRUE)
  </code></pre>
  
  <p>Please help. Thank you. </p>