-
Notifications
You must be signed in to change notification settings - Fork 0
/
corr.R
40 lines (35 loc) · 1.32 KB
/
corr.R
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
31
32
33
34
35
36
37
38
39
40
corr <- function(directory, threshold = 0) {
co<-NULL;
for (i in 1:332) {
if (i<10){
temp<-read.csv(paste(directory,"/",as.character(0),as.character(0),as.character(i),".csv",sep=""));
M<-sum(!is.na(temp["sulfate"])&!is.na(temp["nitrate"]));
if(M>threshold)
{cot<-cor(temp[!is.na(temp["sulfate"])&!is.na(temp["nitrate"]),"sulfate"],temp[!is.na(temp["sulfate"])&!is.na(temp["nitrate"]),"nitrate"]);
co<-c(co,cot);
}
}
else
if(i>=10 & i<100){
x<-paste(directory,"/",as.character(0),as.character(i),".csv",sep="");
temp<-read.csv(x);
M<-sum(!is.na(temp["sulfate"])&!is.na(temp["nitrate"]));
if(M>threshold)
{
cot<-cor(temp[!is.na(temp["sulfate"])&!is.na(temp["nitrate"]),"sulfate"],temp[!is.na(temp["sulfate"])&!is.na(temp["nitrate"]),"nitrate"]);
co<-c(co,cot);
}
}
else
if(i>=100){
x<-paste(directory,"/",as.character(i),".csv",sep="")
temp<-read.csv(x);
M<-sum(!is.na(temp["sulfate"])&!is.na(temp["nitrate"]));
N<-c(N,M);
if(M>threshold)
{cot<-cor(temp[!is.na(temp["sulfate"])&!is.na(temp["nitrate"]),"sulfate"],temp[!is.na(temp["sulfate"])&!is.na(temp["nitrate"]),"nitrate"]);
co<-c(co,cot);
}
}}
co
}