To sum consecutive sets of n elements from each row, you just need to write a function that does the summing and apply it to each row:n <- 3t(apply(y, 1, function(x) tapply(x, ceiling(seq_along(x)/n), sum)))# 1 2 3# [1,] 12 39 66# [2,] 15 42 69# [3,] 18 45 72 这篇关于矩阵中每N个值的总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!