-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcorr.R
More file actions
executable file
·29 lines (22 loc) · 864 Bytes
/
corr.R
File metadata and controls
executable file
·29 lines (22 loc) · 864 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
## 'directory' is a character vector of length 1 indicating
## the location of the CSV files
## 'threshold' is a numeric vector of length 1 indicating the
## number of completely observed observations (on all
## variables) required to compute the correlation between
## nitrate and sulfate; the default is 0
## Return a numeric vector of correlations
## NOTE: Do not round the result!
#Correlation converter
r2 <- c()
corr <- function( directory, threshold = 0 ) {
flist<-paste(directory, "/", dir(directory), sep = "")
for ( nfile in flist ){
nfile_contents <- read.csv(nfile, sep = ",")
nfile_record <- nfile_contents[complete.cases(nfile_contents),]
if ( nrow(nfile_record) > threshold ){
r2 <- c(r2, cor(nfile_record$sulfate, nfile_record$nitrate))
}
}
#Output
r2
}