[R] column names of a correlation matrix

David Winsemius dwinsemius at comcast.net
Wed Oct 28 00:46:03 CET 2009


On Oct 27, 2009, at 10:54 AM, Lee William wrote:

> Hi! All,
> I am working on a correlation matrix of 4217x4217 named 'cor_expN'.  
> I wish
> to obtain pairs with highest correlation values. So, I did this
>> b=matrix(data=NA,nrow=4217,ncol=1)
>> rownames(b)=rownames(cor_expN)
>> for(i in 1:4217){b[i,]=max(cor_expN[i,])}
>> head(b)
>                   [,1]
> aaeA_b3241_14 0.7181912
> aaeB_b3240_15 0.7513084
> aaeR_b3243_15 0.7681684
> aaeX_b3242_12 0.5230587
> aas_b2836_14   0.6615927
> aat_b0885_14    0.6344144
>
> Now I want the corresponding columns for the above values. For that  
> I tried
> this
>> c=matrix(data=NA,nrow=4217,ncol=1)
>> for(i in 1:4217){b[i,]=colnames(max(cor_expN[i,]))}
>
> And got the following error:
> Error in b[i, ] = colnames(max(cor_expN[i, ])) : number of items to  
> replace
> is not a multiple of replacement length
> Any thoughts?

Make a smaller toy example?

-- 
David Winsemius, MD
Heritage Laboratories
West Hartford, CT




More information about the R-help mailing list