r - can we merge two functions into one in correlations calculations? -
this code worked fine , got results like:
dir1 <- list.files("d:thly", "*.bin", full.names = true) dir2 <- list.files("d:002", "*.envi", full.names = true) file_tot <- array(dim = c(1440, 720, 11, 2)) resultscor<-apply(file_tot,c(1,2),function(x){cor(x[,1],x[,2],use = "na.or.complete")})
i calculate correlation when p-value lower 0.05
. function job:
return_cor = function(x, y) { z = cor.test(x,y) if(z[[3]] < 0.05) { return(z[[5]]) } else { return(na) } }
however got error:
error in cor.test.default(x, y) : not plenty finite observations
both functions worked perfectly.how can merge both functions 1 function calculate correlation when p value (certain value, threshold) , calculations if there less 3 pairs.
the question not clear,
if want calculation if p>0.5,
you can add together assertion, or simple if before executing function:
somethings like:
if (isvalid(x,y)) homecoming function(x,y); else homecoming na;
where isvalid function posted checks if x,y close plenty you.
r correlation
No comments:
Post a Comment