You can define the following function f
f <- function(mat, submat.size = 3) {
ridx <- Filter(function(x) length(x) == submat.size, split(sample(seq(nrow(mat))), ceiling(seq(nrow(mat)) / submat.size)))
cidx <- Filter(function(x) length(x) == submat.size, split(sample(seq(ncol(mat))), ceiling(seq(ncol(mat)) / submat.size)))
replicate(2, mat[ridx[[sample(length(ridx), 1)]], cidx[[sample(length(cidx), 1)]]], simplify = FALSE)
}
and this function enables you to generate a pair of sub-matrices which are random and non-overlapped.
Example Result
> f(matriz)
[[1]]
[,1] [,2] [,3]
[1,] 68 67 70
[2,] 38 37 40
[3,] 88 87 90
[[2]]
[,1] [,2] [,3]
[1,] 63 62 69
[2,] 33 32 39
[3,] 83 82 89
If you want all possible exclusive random sub-matrices each time, you can try
f2 <- function(mat, submat.size = 3) {
ridx <- Filter(function(x) length(x) == submat.size, split(sample(seq(nrow(mat))), ceiling(seq(nrow(mat)) / submat.size)))
cidx <- Filter(function(x) length(x) == submat.size, split(sample(seq(ncol(mat))), ceiling(seq(ncol(mat)) / submat.size)))
r <- list()
for (i in seq_along(ridx)) {
for (j in seq_along(cidx)) {
r[[length(r) + 1]] <- mat[ridx[[i]], cidx[[j]]]
}
}
r
}
and you will obtain
> f2(matriz)
[[1]]
[,1] [,2] [,3]
[1,] 3 6 5
[2,] 63 66 65
[3,] 83 86 85
[[2]]
[,1] [,2] [,3]
[1,] 2 8 4
[2,] 62 68 64
[3,] 82 88 84
[[3]]
[,1] [,2] [,3]
[1,] 1 10 7
[2,] 61 70 67
[3,] 81 90 87
[[4]]
[,1] [,2] [,3]
[1,] 13 16 15
[2,] 33 36 35
[3,] 23 26 25
[[5]]
[,1] [,2] [,3]
[1,] 12 18 14
[2,] 32 38 34
[3,] 22 28 24
[[6]]
[,1] [,2] [,3]
[1,] 11 20 17
[2,] 31 40 37
[3,] 21 30 27
[[7]]
[,1] [,2] [,3]
[1,] 43 46 45
[2,] 53 56 55
[3,] 73 76 75
[[8]]
[,1] [,2] [,3]
[1,] 42 48 44
[2,] 52 58 54
[3,] 72 78 74
[[9]]
[,1] [,2] [,3]
[1,] 41 50 47
[2,] 51 60 57
[3,] 71 80 77