Hi,
I have a correlation matrix of about 3000 items, i.e., a 3000*3000
matrix. For each of the 3000 items, I want to get the top 50 items that
have the highest correlation with it (excluding itself) and generate a
data frame with 3 columns like (ID, ID2, cor), where ID is those
3000 items each
a possible vectorized solution is the following:
cor.mat - cor(matrix(rnorm(100*1000), 1000, 100))
p - 30 # how many top items
n - ncol(cor.mat)
cmat - col(cor.mat)
ind - order(-cmat, cor.mat, decreasing = TRUE) - (n * cmat - n)
dim(ind) - dim(cor.mat)
ind - ind[seq(2, p + 1), ]
out - cbind(ID
Works like a charm, thank you!
-Original Message-
From: Dimitris Rizopoulos [mailto:d.rizopou...@erasmusmc.nl]
Sent: Thursday, February 12, 2009 12:11 PM
To: Tan, Richard
Cc: r-help@r-project.org
Subject: Re: [R] get top 50 correlated item from a correlation matrix
for each item
Statistician
Research Institute on Addictions
University at Buffalo
SUNY
Tan, Richard r...@panagora.com
Sent by: r-help-boun...@r-project.org
02/12/2009 11:19 AM
To
r-help@r-project.org
cc
Subject
[R] get top 50 correlated item from a correlation matrix for each item
Hi,
I have a correlation
4 matches
Mail list logo