SolitonK SolitonK - 1 year ago 106
R Question

R, Cumsum function on non-concatinative variable realisations

I have a 306x19 data-set and I would like to use the Cumsum function on say, VarF only when VarA takes a certain value.

On a high-level description, the idea is to filter on VarA and apply a cumsum on the remaining of the dataset (VarF).

I would appreciate any pointers here guy on how to solve this.

Answer Source

Have you tried using the ifelse function? Something like this should work:

cumsum(ifelse(VarA == value, VarF, 0))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download