title: warning message in mean.default argument is not numeric or logical returning na but my vector is numeric
body: <p>i am running this R code to import a lot of csv file and calculate one mean of a numerico vector (nitrate) for all the datasets filtering by some values of an integer vector, ID.</p>
  
  <pre><code>setwd("C:/Users/americo/Documents/Documenti_2_0/Education/Data science/Coursera/R programming/rworkingdir/specdata")
  lista_tot1 = list.files(pattern="*.csv");
  lista_tot2 = lapply(lista_tot1, read.csv, sep = ",")#stampa tutti i csv                                  
  lista_tot3&lt;-do.call("rbind", lista_tot2)
  lista_tot&lt;-lista_tot3[is.element(lista_tot3$ID, 3:4),]
  media&lt;-mean(lista_tot$nitrate, na.rm=TRUE)
  media
  </code></pre>
  
  <p>and it works.</p>
  
  <p>But if i try to write this function, which seems similar to me:</p>
  
  <pre><code>pollutantmean &lt;- function(directory, pollutant, id = 1:332) {
    setwd(directory)
    lista_tot1 = list.files(pattern="*.csv");
    lista_tot2 = lapply(lista_tot1, read.csv, sep = ",")  
    lista_tot3&lt;-do.call("rbind", lista_tot2)
    lista_tot&lt;-lista_tot3[is.element(lista_tot3$ID, id),]
    media&lt;-mean(lista_tot$pollutant), na.rm=TRUE)
    return(media)
  }
  </code></pre>
  
  <p>and then</p>
  
  <pre><code>media1&lt;-pollutantmean("C:/Users/americo/Documents/Documenti_2_0/Education/Data science/Coursera/R programming/rworkingdir/specdata","nitrate", 3:4)
  </code></pre>
  
  <p>it then returns to me the message:</p>
  
  <pre><code>warning message in mean.default argument is not numeric or logical returning na 
  </code></pre>
  
  <p>...but my vector is numeric</p>
  
  <p>that really doesn't make sense to me.
  if i ask to return of the structure of the last dataset, lista_tot, nitrate is still numeric.</p>
  
  <p>I really don't know what to do, if some very experienced user could help me i would be extremely grateful.</p>