# howto join matrices produced by rcorr()

3 messages
Open this post in threaded view
|

## howto join matrices produced by rcorr()

 Hi, i have used rcorr() for calculating pearsons r and according p-values for my data, giving me 2 matrices. Now I would like to print scatterplots for all results with "good" correlation values. So i need a way to extract the row-name and column-name for each item in the matrix with "good" r-values, so i can use them in the plot()-function on my original dataframe programmatically. below is what i have got - and now i'm stuck: -------------------------------------- incomingData <- read.csv(inputfile, header=TRUE, na="NA") datamatrix <- data.matrix(incomingData) library(Hmisc) output <- rcorr(datamatrix, type="pearson") # get short variables to ease reading r <- output\$r n <- output\$n P <- output\$P r[n<5]<-NA # ignore less than five observations r[r>-0.5 & r<0.5]<-NA # take only "good" korrelations P[is.na(r)]<-NA # delete P values for deleted korrelations r <- format(round(cbind(rep(-1.11, ncol(r)), r), 2))[,-1] ## trunctuate matrix with correlations to 2 decimals P <- format(round(cbind(rep(-1.11, ncol(P)), P), 4))[,-1] ## trunctuate matrix with P-Values to 4 decimals make_plot <- function(a,b,Rval,Pval,aname,bname) {         png(paste(aname,'_vs_',bname,'.png', sep=""))         plot(a,b, main="Rval(p=Pval)")         fitline <- lm(a~b)         abline(fitline)         dev.off() } ------------------------------------- Big Thanks for any ideas on this, Alex ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.