This question might be a duplicate but still asking!
I have this list where i need to do a conditional sum over the positve and negative values. i could do this with data table using this. But im looking for a base R solution.
list1 = list(
x=c(1,1,-1,-1,1),
y=c(-1,-1,1,-1,-1)
)
lapply(list1, function(x) ave(x, rleid(x), FUN = cumsum))
$x
[1] 1 2 -1 -2 1
$y
[1] -1 -2 1 -1 -2