[R] How to calculate average correlation coefficient of a correlation matrix ?
Chuck Cleland
ccleland at optonline.net
Tue Oct 13 16:38:38 CEST 2009
On 10/13/2009 10:13 AM, Amit Kumar wrote:
> Hi! All,
> I have large correlation matrix Cor. I wish to calculate average
> correlation coefficient for this matrix.
> Is there any function in R to do this?
> Thanks in advance.
cormat <- cor(iris[,1:4])
corlowtri <- cormat[lower.tri(cormat)]
corlowtri
[1] -0.1175698 0.8717538 0.8179411 -0.4284401 -0.3661259 0.9628654
mean(corlowtri)
[1] 0.2900708
mean(abs(corlowtri))
[1] 0.594116
avgcor <- function(x){mean(abs(x[lower.tri(x)]))}
avgcor(cor(iris[,1:4]))
[1] 0.594116
> Amit
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
--
Chuck Cleland, Ph.D.
NDRI, Inc. (www.ndri.org)
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894
More information about the R-help
mailing list