Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

How to convert multiple defferent correlation matrix in dataframe by pairs in one time?

$
0
0

I want to convert the multiple correlation matrix into dataframe at the same time

my matrix group like this: [enter image description here

the output I want like this: enter image description here

my current code is like this:

dat1 <- read.xlsx("correlation reshape.xlsx",sheet=1,rows=1:7,cols=2:8)#read studyid1-James2005
dat1
reshape_1<-as_cordf(dat1)#reshape the data into matrix
reshape_1
long.format1<-reshape_1 %>% gather(-rowname, key = "colname", value = "cor")#reshape the data into 
na1<-na.omit(long.format1)#omit NA value
## psychmeta
dat2 <- read.xlsx("correlation reshape.xlsx", sheet=1,rows=8:11,cols=2:5,skipEmptyCols=TRUE)#read studyid2-Ashforth2010
reshape_2<-as_cordf(dat2)
long.format2<-reshape_2 %>% gather(-rowname, key = "colname", value = "cor")
long.format2
na2<-na.omit(long.format2)
#output method1 
c <- rbind(na1,na2)#combine na1,na2..., and put them out.
write.table(c,"reshape_output.csv",sep=",")

my current method is to sperate the two correlation matrix, but i will have more than 1000 different correlation matrix, i want to know how to process them at the same time into the dataframe by pairs and add the ID as the first column? pls help


Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>