這裏的成3列
#DATA
set.seed(42)
m = matrix(rnorm(90), ncol = 9)
sapply(split(sequence(NCOL(m)), ceiling(sequence(NCOL(m))/3)), function(i) rowMeans(m[,i]))
# 1 2 3
# [1,] 0.78972984 0.3277913 0.03411781
# [2,] -0.01978707 -0.1466863 0.11765521
# [3,] -0.39921655 1.1229981 0.43126071
# [4,] 0.52291618 -0.2309106 0.10843898
# [5,] 0.72204682 -0.2578551 -0.82148326
# [6,] 0.03311892 -0.3358800 0.83184534
# [7,] 0.32333323 -0.3055211 0.29562900
# [8,] -1.50475918 0.2276755 0.43983899
# [9,] 0.01268471 -1.9462480 0.32276620
#[10,] 0.20580146 0.3255511 0.14762346
平均9列的一個例子