Hello Gurus I have two correlation matrices 'xa' and 'xb' set.seed(100) d=cbind(x=rnorm(20)+1, x1=rnorm(20)+1, x2=rnorm(20)+1) d1=cbind(x=rnorm(20)+2, x1=rnorm(20)+2, x2=rnorm(20)+2) xa=cor(d,use='complete') xb=cor(d1,use='complete') I want to combine these two to get a third matrix which should have half values from 'xa' and half values from 'xb' x x1 x2 x 1.0000000 -0.15157123 -0.23085308 x1 0.3466155 1.00000000 -0.01061675 x2 0.1234507 0.01775527 1.00000000 I would like to generate a heatmap for correlation values in disease and non disease phenotype I would appreciate if someone can point me in correct direction. Thanks sharad -- View this message in context: http://r.789695.n4.nabble.com/correlation-matrix-tp3891085p3891085.html Sent from the R help mailing list archive at Nabble.com.
okay so fixed what i need to do this way finit=0 for(ri in 1:dim(xa)[1]) { finit=finit+1 xc[ri,1:finit]<-xa[ri,1:finit] xc[1:finit,ri]<-xb[1:finit,ri] } but getting error in heatmap.2> mycol <- colorpanel(n=40,low="red",mid="white",high="blue") > heatmap.2(xc, breaks=pairs.breaks, col=mycol, Rowv=FALSE, symm=TRUE, > key=TRUE, symkey=FALSE, density.info="none", trace="none", cexRow=0.5,+ scale = "none", dendrogram="none") Error in heatmap.2(xc, breaks = pairs.breaks, col = mycol, Rowv = FALSE, : `x' must be a numeric matrix any pointers are appreciated -- View this message in context: http://r.789695.n4.nabble.com/correlation-matrix-tp3891085p3891584.html Sent from the R help mailing list archive at Nabble.com.
What a pleasant post to respond to - with self-contained code. :) heat<-matrix(0,nrow=dim(xa)[1],ncol=dim(xa)[2]) heat[lower.tri(heat)]<-xa[lower.tri(xa)] heat[upper.tri(heat)]<-xb[upper.tri(xb)] diag(heat)<-1 heat HTH, Daniel 1Rnwb wrote:> > Hello Gurus > I have two correlation matrices 'xa' and 'xb' > set.seed(100) > d=cbind(x=rnorm(20)+1, > x1=rnorm(20)+1, > x2=rnorm(20)+1) > > > d1=cbind(x=rnorm(20)+2, > x1=rnorm(20)+2, > x2=rnorm(20)+2) > > xa=cor(d,use='complete') > > xb=cor(d1,use='complete') > > > > I want to combine these two to get a third matrix which should have half > values from 'xa' and half values from 'xb' > x x1 x2 > x 1.0000000 -0.15157123 -0.23085308 > x1 0.3466155 1.00000000 -0.01061675 > x2 0.1234507 0.01775527 1.00000000 > > I would like to generate a heatmap for correlation values in disease and > non disease phenotype > > I would appreciate if someone can point me in correct direction. > Thanks > sharad >-- View this message in context: http://r.789695.n4.nabble.com/correlation-matrix-tp3891085p3891685.html Sent from the R help mailing list archive at Nabble.com.
Tena koe Sharad If I understand you correctly, you want the lower triangle of your combined matrix to be the lower triangle of one of the correlation matrices, and the upper triangle to be the upper triangle from the other. If so, check lower.tri() and upper.tri(). HTH .... Peter Alspach> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of 1Rnwb > Sent: Tuesday, 11 October 2011 6:20 a.m. > To: r-help at r-project.org > Subject: [R] correlation matrix > > Hello Gurus > I have two correlation matrices 'xa' and 'xb' > set.seed(100) > d=cbind(x=rnorm(20)+1, > x1=rnorm(20)+1, > x2=rnorm(20)+1) > > > d1=cbind(x=rnorm(20)+2, > x1=rnorm(20)+2, > x2=rnorm(20)+2) > > xa=cor(d,use='complete') > > xb=cor(d1,use='complete') > > > > I want to combine these two to get a third matrix which should have > half > values from 'xa' and half values from 'xb' > x x1 x2 > x 1.0000000 -0.15157123 -0.23085308 > x1 0.3466155 1.00000000 -0.01061675 > x2 0.1234507 0.01775527 1.00000000 > > I would like to generate a heatmap for correlation values in disease > and non > disease phenotype > > I would appreciate if someone can point me in correct direction. > Thanks > sharad > > -- > View this message in context: > http://r.789695.n4.nabble.com/correlation-matrix-tp3891085p3891085.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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.The contents of this e-mail are confidential and may be subject to legal privilege. If you are not the intended recipient you must not use, disseminate, distribute or reproduce all or any part of this e-mail or attachments. If you have received this e-mail in error, please notify the sender and delete all material pertaining to this e-mail. Any opinion or views expressed in this e-mail are those of the individual sender and may not represent those of The New Zealand Institute for Plant and Food Research Limited.