I would like to subset the data of one matrix using data in a second matrix. The columns of one matrix is labeled. For example,
area1 <- c(9836374,635440,230
I think this covers it and fits with your description:
spl <- cumsum(apply(mat2,1, function(x) all(x==c(1,2,5))))
split(as.data.frame(mat1),spl)
#$`1`
# a1 a2 a3
#1 9836374 635440 23018
#2 833696 936079 1472449
#
#$`2`
# a1 a2 a3
#3 879042 220539 870581
#
#$`3`
# a1 a2 a3
#4 217418 552303 269359
#
#$`4`
# a1 a2 a3
#5 833696 936079 1472449
#6 879042 220539 870581
#7 833696 936079 1472449
#8 879042 220539 870581
The result fits with "submatrix 1 would have 2 rows of data, submatrix 2 and 3 have 1 row each, and submatrix 4 would have 4 rows of data from mat1"