r - How can I create a sum of every n numbers? -


this question has answer here:

i have dataframe column:

1 1 1 1 2 2 2 2 3 3 3 3 

and want sum every n numbers (say 4). intended output:

4 8 12 

how can this? know how rollsum, wanted know if there function this?

x <- data.frame(value = c(1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3)) x$group = rep(1:(nrow(x)/4), each=4)  tapply(x$value, x$group, fun = sum) 

the hardest part here assigning groups. see ?rep details there.


Comments

Popular posts from this blog

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -

javascript - Using jquery append to add option values into a select element not working -

javascript - Restarting Supervisor and effect on FlaskSocketIO -