Skip to content

Instantly share code, notes, and snippets.

@xingpel
Last active August 29, 2015 14:05
Show Gist options
  • Save xingpel/8cf164a131eb161626a8 to your computer and use it in GitHub Desktop.
Save xingpel/8cf164a131eb161626a8 to your computer and use it in GitHub Desktop.
Merge selected csv files based on name and (calculate means)
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