I would like to make subgroups for a matrix, and each subgroup contains different amount of columns. For example, there is a matrix with 1000 rows and 420 columns, and I would like to split into 35 sub-matrix in order, like first one contains the first 12 cols, and the second contains the first 24 cols, the third one contains the first 36 cols so on?
Asked
Active
Viewed 106 times
0
-
1Hello. Please include a reproducible example along with expected output and code you have tried so far. Additionally, [look at this link](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) for further info. – Sotos May 10 '16 at 09:02
-
Did you calculated the need of RAM? Do you need all submatrices at once? – jogo May 10 '16 at 09:19
-
Possible duplicate of [split big matrix in subsets,R](http://stackoverflow.com/questions/37113620/split-big-matrix-in-subsets-r) – jogo May 10 '16 at 10:02
1 Answers
0
If M
is your matrix with 1000 rows and 420 columns
this will give you a list of the desired matrices:
lapply(seq(12, 420, by=12), function(x) M[, 1:x])
This will need a lot of RAM. If you don't need all submatrices at once you can do a loop:
for (x in seq(12, 420, by=12)) {
subM <- M[, 1:x]
# .... use subM
}

jogo
- 12,469
- 11
- 37
- 42
-
Thanks Jogo! Yes, I will need to have all matrices at once, possible to achieve that? – Amanda May 10 '16 at 09:33
-
1In which form you need the matrices? Please edit your question http://stackoverflow.com/posts/37133542/edit The `lapply()` gives you a list of the matrices. You can thank by accepting the answer. – jogo May 10 '16 at 09:38