标签:
1 Correlation<- function(x,y) { 2 len<-length(x) 3 if( len != length(y)) 4 stop("length not equal!") 5 6 x2 <- unlist(lapply(x,function(a) return(a^2))) 7 y2 <- unlist(lapply(y,function(a) return(a^2))) 8 xy <- x*y 9 10 a <- sum(xy)*len - sum(x)*sum(y) 11 b <- sqrt(sum(x2)*len - sum(x)^2)*sqrt(sum(y2)*len - sum(y)^2) 12 if( b == 0) 13 stop("data is incorrect!") 14 return(a/b) 15 }
标签:
原文地址:http://www.cnblogs.com/chance88/p/4957230.html