forked from rdpeng/ProgrammingAssignment2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPollutant.R
More file actions
24 lines (19 loc) · 1000 Bytes
/
Pollutant.R
File metadata and controls
24 lines (19 loc) · 1000 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
pollutantmean <- function(directory, pollutant, id) {
## 'directory' is a character vector of length 1 indicating the location of
## the CSV files
## 'pollutant' is a character vector of length 1 indicating the name of the
## pollutant for which we will calculate the mean; either 'sulfate' or
## 'nitrate'.
## 'id' is an integer vector indicating the monitor ID numbers to be used
## Return the mean of the pollutant across all monitors list in the 'id'
## vector (ignoring NA values)
data = numeric()
for (i in id) {
newRead = read.csv(paste(directory, "/", formatC(i, width = 3, flag = "0"),
".csv", sep = ""))
data = c(data, newRead[[pollutant]])
}
return(mean(data, na.rm = TRUE))
print (mean(data, na.rm = TRUE))
}
pollutantmean("specdata", "nitrate", 23)