Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
16 lines (15 sloc) 805 Bytes
# takes a directory of data files and a threshold for complete cases and calculates the correlation
#between sulfate and nitrate for monitor locations where the number of completely observed cases (on all variables)
#is greater than the threshold. The function should return a vector of correlations for the monitors that meet the threshold requirement.
#If no monitors meet the threshold requirement, then the function should return a numeric vector of length 0.
corr <- function(directory, threshold = 0) {
FL<- list.files(path = directory, pattern = ".csv", full.names = TRUE)
cors <- numeric()
for (i in 1:332) {
dat <- read.csv(FL[i])
if (sum(complete.cases(dat)) > threshold) {
cors <- c(cors, cor(dat[["sulfate"]], dat[["nitrate"]], use = "complete.obs"))
}
}
cors
}
You can’t perform that action at this time.