Apply function on every four rows
You could use tapply or aggregate:

set.seed(1)
X &lt;- matrix(rnorm(30), nrow=100, ncol=6)
id &lt;- ceiling(seq_len(nrow(X))/4)

tapply(X[, 3], id, sum)
#       1       2       3       4       5       6       7       8       9      10 
# -0.2137 -1.0629 -0.5030  0.2687  1.4961 -0.9343  2.0076  3.1162 -1.3511 -1.6868

aggregate(X[, 3], by=list(id), FUN=sum)
#    Group.1       x
# 1        1 -0.2137
# 2        2 -1.0629
# 3        3 -0.5030
# 4        4  0.2687
# 5        5  1.4961
# 6        6 -0.9343
# 7        7  2.0076
# 8        8  3.1162
# ...

# check results
sum(X[1:4, 3])
# [1] -0.2137
sum(X[5:8, 3])
# [1] -1.063