-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcorr.R
More file actions
30 lines (27 loc) · 937 Bytes
/
corr.R
File metadata and controls
30 lines (27 loc) · 937 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
27
28
29
30
corr <- function(directory, threshold = 0) {
setwd("J:/R")
source("complete.R")
list <- complete(directory)
list <- list[which (list$nobs > threshold),]
if (dim(list)[1] > 0){
for (i in list$id) {
if (i < 10) {
temp <- read.csv(paste("00",i,".csv",sep=""))
} else if (i >= 10 & i < 100) {
temp <- read.csv(paste("0",i,".csv",sep=""))
} else if (i >= 100) {
temp <- read.csv(paste(i,".csv",sep=""))
}
temp <- temp[which( !is.na(temp$Date) & !is.na(temp$sulfate) & !is.na(temp$nitrate)), ]
if (exists("corrs")) {
j <- length(corrs)+1
corrs[j] <- cor(temp$sulfate, temp$nitrate)
} else {
corrs <- cor(temp$sulfate, temp$nitrate)
}
}
} else {
corrs <- vector()
}
corrs
}