Skip to content
Prev 305776 / 398506 Next

Conditional operations in R

On Tue, Sep 18, 2012 at 3:41 PM, ramoss <ramine.mossadegh at finra.org> wrote:
If I understand the algorithm correctly, you take a cumulative sum of
the pct_total column and want the index of the first place that passes
50%:

try

with(DATA, which.max(cumsum(pct_total) > 0.5))

which is admittedly rather opaque.

Also in: top <- client[c(1,4),]

That's not rows 1 to 4 but rows one and 4: you need instead: seq(1,4)
to make c(1,2,3,4).

Cheers,
Michael