I have a list of matrices that all have the same number of columns but that have varying number and naming of rows. They look something like this:
$Name1
c1 c2 c3 c4 c5 c6
Spec1 0 2 0 1 0 0
Spec2 1 0 1 0 0 0
Spec3 1 0 1 0 0 0
$Name2
c1 c2 c3 c4 c5 c6
Spec1 0 0 0 0 1 0
Spec4 0 0 0 1 0 0
Spec5 0 0 0 0 0 1
I'm trying to get them all into one one dataframe, while preserving both the rownames as well as the names of the matrices. Something like this is what I'm trying to get:
c1 c2 c3 c4 c5 c6
Name1Spec1 0 2 0 1 0 0
Name1Spec2 1 0 1 0 0 0
Name1Spec3 1 0 1 0 0 0
Name2Spec1 0 0 0 0 1 0
Name2Spec4 0 0 0 1 0 0
Name2Spec5 0 0 0 0 0 1
do.call(rbind,...) gets the data how I want it, but I haven't been able to figure out how to get the names to be preserved or concatenate like that. I've also tried a few ways to make the name list separately and failed on those fronts. The final dataframe should be 1113 rows, but there are 358 matrices in the list. I've tried many inelegant things, but I figure something like this should be close?
list.names<-list()
for(i in 1:length(ListofMatrices)){
list.names[i]<-rownames(ListofMatrices[[i]])
}
I feel like I'm missing something plainly obvious with lapply or setting up a loop.