Applying function to consecutive subvectors of equal size
问题 I am looking for a nice and fast way of applying some arbitrary function which operates on vectors, such as sum , consecutively to a subvector of consecutive K elements. Here is one simple example, which should illustrate very clearly what I want: v <- c(1, 2, 3, 4, 5, 6, 7, 8) v2 <- myapply(v, sum, group_size=3) # v2 should be equal to c(6, 15, 15) The function should try to process groups of group_size elements of a given vector and apply a function to each group (treating it as another