Q:

Get multiple/grouped sums for a vector with values separated by NA's

I have an update on my previous question:
c(123, 4525, 4365, 234, 674, NA, NA, NA, NA, NA, NA, NA, 
  24, 347, 457, 3246, 234, 5, 346, NA, NA, NA, NA, NA, NA) # [... and so on]

Is there any way to get me the sums for each of my pack of values separated by my NA's? Both the values and the NA's separate in their length over the vector and that's where I see the problem…
Ronak Shah's answer was very helpful but there remains a problem:
I have some packs of values, which equal 0 in their sum.
But this is an important information for me!
So if I use new[new != 0] I cut them off and I have no information on which sums belong to which pack of values in the end.

A:

You could use data.table::rleid :
library(data.table)
tapply(x[!is.na(x)], rleid(is.na(x))[!is.na(x)], sum)
#    1    3    5    7    9 
# 9921 4659 5289    0    0 

