-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathpollutantmean_Lu.R
More file actions
26 lines (22 loc) · 819 Bytes
/
pollutantmean_Lu.R
File metadata and controls
26 lines (22 loc) · 819 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
25
26
pollutantmean <- function(directory, pollutant, id = 1:332) {
## '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)
list<-list.files()
target<-c()
id = 4:300
pollutant = "nitrate"
for (i in id){
x<-read.csv(list[i])
data<-x[pollutant]
good<-data[!is.na(data)]
target<-c(target,good) #concatenates "good" data into 'target' vector and then appends new data to the end.
}
mean(target)
}