big_hand_monster
(a <- matrix(1:20,nrow=4,byrow = TRUE))
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 1 2 3 4 5
#> [2,] 6 7 8 9 10
#> [3,] 11 12 13 14 15
#> [4,] 16 17 18 19 20
(b <- matrix(21:40,nrow=4,byrow = TRUE))
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 21 22 23 24 25
#> [2,] 26 27 28 29 30
#> [3,] 31 32 33 34 35
#> [4,] 36 37 38 39 40
sapply(seq_len(nrow(a)),function(x) sapply(seq_len(nrow(b)), function(y) mean(a[x,])+mean(b[y,])))
#> [,1] [,2] [,3] [,4]
#> [1,] 26 31 36 41
#> [2,] 31 36 41 46
#> [3,] 36 41 46 51
#> [4,] 41 46 51 56
<sup>Created on 2021-05-17 by the reprex package (v0.3.0)</sup>
嗨呀,一个道理的。取决于你matrix的每一行是怎么作为参数的。在最里面的那个function操作即可