Pollutantmean Assignments

This question already has an answer here:

This is the first time I'm trying to import multiple CSV files in R and to solve that part of the assignment, using some of the csv files to calculate the mean of sulfate and nitrate. I searched for answers here in stackoverflow and other sites but I wasn't able to fix that issue based on what is told in questions here about the topic. I'm also new in R Programming.

If its useful: R version is 3.2.1 Mac OS X version 10.7.5

I have an assignment in Coursera where I have 332 CSV files that I have to calculate the mean of pollutants.

Link to download the file: https://d396qusza40orc.cloudfront.net/rprog%2Fdata%2Fspecdata.zip

Assignment Part 1:

Write a function named 'pollutantmean' that calculates the mean of a pollutant (sulfate or nitrate) across a specified list of monitors. The function 'pollutantmean' takes three arguments: 'directory', 'pollutant', and 'id'. Given a vector monitor ID numbers, 'pollutantmean' reads that monitors' particulate matter data from the directory specified in the 'directory' argument and returns the mean of the pollutant across all of the monitors, ignoring any missing values coded as NA.

Prototype of the function:

My outcome should be that:

I already created my working directory and this is were I wasn't able to go further.

Whenever I try to do use F1 <-read.csv("name of the file", header=TRUE) the error that appears is Error in file(file, "rt") : not possible to open a connection In addition: Warning message: In file(file, "rt") : not possible to open the file 'nameoffile.csv': No such file or directory When I use the command read.table(filechoose(), header=TRUE) works for all the files except for the first file (001.csv) which says Error in scan (file, what, nmax, sep, dec, quote, skip, nlines, na.strings, : line 1 don't have 7 elements When I try sapply(filelist, read.csv) appears the same error. When I use read.csv, sapply or lapply for the "specdata" the error is Error in read.table(file = file, header = header, sep = sep, quote = quote,: no lines available in input although I have all the 332.csv files in the "specdata" file.

I hope I posted everything needed for a reproducible exercise. If there is anything more needed, just let me know.

Thanks !

rcsvmultiple-files

The function named 'pollutantmean' calculates the mean of a pollutant (sulfate or nitrate) across a specified list of monitors. The function 'pollutantmean' takes three arguments: 'directory', 'pollutant', and 'id'. Given a vector monitor ID numbers, 'pollutantmean' reads that monitor's particulate matter data from the directory specified in the 'directory' argument and returns the mean of the pollutant across all of the monitors, ignoring any missing values coded as NA. This is part of [Introduction to R programming course](https://www.coursera.org/course/rprog) The following figure shows the final pollutant mean for various sensors. ![](http://neerajkh.blob.core.windows.net/images/ass1part1_2.PNG) The experiment graph for this assignment is shown below. For this experiment, we uploaded dataset as zip file, created sample test input as part of enter module data, and finally wrote the function as a script in **Execute-R** module. ![](http://neerajkh.blob.core.windows.net/images/ass1part1.PNG) Created by a Microsoft Employee

0 thoughts on “Pollutantmean Assignments”

    -->

Leave a Comment

Your email address will not be published. Required fields are marked *