Last active
August 29, 2015 14:05
-
-
Save xingpel/da3edb30d1e375e5cb57 to your computer and use it in GitHub Desktop.
Take the csv files above the threshold of complete file(rows without any NA) and check the covariance of them all together
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
corr <- function(directory, threshold = 0) { | |
result <- NULL | |
#for each csv file, use function complete() to obtain the complete number and | |
#compare with threshold | |
for (i in 1:332) { | |
# get the number into 000 format, exp: 1 -> 001 | |
num <- sprintf("%03d",i) | |
# read the file and saved to data | |
path <- paste(directory,num,".csv",sep="") | |
data <- read.csv(path) | |
t <- complete(directory,i) | |
# get the nobs number and compare to threshold. | |
if (t[,2] > threshold){ | |
correlations <- cor(data$sulfate,data$nitrate,use="complete.obs") | |
result <- c(result,correlations) | |
} | |
} | |
result | |
} | |
# this function requires the previous function: complete(). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment