Error in file(file, "rt") : cannot open the connection in r
<p>I am new to programming.Currently doing R programming in coursera and got this error while doing assignment named "pollutantmean".I searched in forums and stackoverflow,but couldnt able to fix it.Appreciate your help.Thanks.</p>

<p>I got this error : </p>

<pre><code>Error in file(file, "rt") : cannot open the connection In addition: Warning message:
In file(file, "rt") : cannot open file 'NA': No such file or directory
</code></pre>

<p>Note: I have a folder "specdata" which is the working directory.This "specdata" has all the 332 csv files.I want to calculate mean for one of the pollutant column named "pollutant" in those files and "directory" is the location of those files."id" is a integer vector mentioning the monitor number.so,here is my code:</p>

<pre><code> pollutantmean &lt;- function(directory, pollutant, id = 1:332) {            

    files_full &lt;- list.files(directory, full.names = TRUE) 

    dat &lt;- data.frame()

    for (i in id) {
    dat &lt;- rbind(dat, read.csv(files_full[i]))
    }

    mean(dat[, pollutant], na.rm = TRUE)
    }

    pollutantmean("specdata","sulfate",id = 1:10)
</code></pre>