creating a larger matrix from smaller matrices in R -


i have series of text files in folder called "disintegration t1" this:

> 1.txt 0   0   0   0   1 1   0   0   0   1 0   1   0   0   1 0   0   0   0   0 1   1   1   1   0 > 2.txt 0   1   1   0   1 0   0   1   1   1 1   1   0   1   1 1   1   1   0   1 0   0   0   0   1 > 3.txt 0   1   1   1 1   0   0   0 0   0   0   0 1   0   0   0 

the files either 4x4 or 5x5. must read in matrices, data social network analyses. goal automate process of putting these matrices larger matrix, these matrices directly diagonal each other, , 0s inputted in blank spaces within larger matrix. in case final result like:

> mega_matrix 0   0   0   0   1   0   0   0   0   0   0   0   0   0 1   0   0   0   1   0   0   0   0   0   0   0   0   0 0   1   0   0   1   0   0   0   0   0   0   0   0   0 0   0   0   0   0   0   0   0   0   0   0   0   0   0 1   1   1   1   0   0   0   0   0   0   0   0   0   0 0   0   0   0   0   0   1   1   0   1   0   0   0   0 0   0   0   0   0   0   0   1   1   1   0   0   0   0 0   0   0   0   0   1   1   0   1   1   0   0   0   0 0   0   0   0   0   1   1   1   0   1   0   0   0   0 0   0   0   0   0   0   0   0   0   1   0   0   0   0 0   0   0   0   0   0   0   0   0   0   0   1   1   1 0   0   0   0   0   0   0   0   0   0   1   0   0   0 0   0   0   0   0   0   0   0   0   0   0   0   0   0 0   0   0   0   0   0   0   0   0   0   1   0   0   0 

thank you!

you want bdiag matrix package:

library(matrix) bdiag(matrix1, matrix2, matrix3) 

and whole directory (thanks @user20650 in comments) :

bdiag(lapply(dir(), function(x){as.matrix(read.table(x))})) 

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -