The best thing to do is first use
do.call(rbind,res)
then with a single matrix containing all list sub matrices add one more column And one more column to label the rows of each sub matrix. So if your your sub matrices has 3 rows each, the this column will look like: 1,2,3,1,2,3,...,1,2,3
e.g
singleMatrix=do.call(rbind,res)
rowindex=rep(c(1:numberOfRowsOfSubMatrix,numberOfSubMatrices)
Then form a combined data frame with the indicator
, singMatrix
and rowindex
Matrix=data.frame(singleMatrix,indicator,rowindex)
Now if indicator==0
delete the row and delete all rows with thesame rowindex
number.