Last active
August 29, 2015 14:05
-
-
Save xingpel/8cf164a131eb161626a8 to your computer and use it in GitHub Desktop.
Merge selected csv files based on name and (calculate means)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pollutantmean <- function(directory, pollutant, id = 1:332) { | |
#1, read id csv files and merge into one datafile called data. | |
data <- NULL | |
for (i in id) { | |
count <- sprintf("%03d",i) | |
path <- paste(directory,count,".csv",sep="") | |
data <- rbind(data, read.csv(path)) | |
} | |
#2, return the mean of the specific pollutant, | |
#with variable precision = 4 | |
a <- mean(data[,pollutant],na.rm=TRUE) | |
print(a,digits=4) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment