[R] Summing using a boolean index vector (repost in plain text).

Dan Stanger DStanger at EatonVance.Com
Fri Jun 18 17:39:33 CEST 2010


Hello all:
I have a dataframe f of weekdays and value, and a Boolean vector with Fridays set to true, and other days set to false, created by fridays<-(diff(f$weekdays) < -1).
I would like to create a vector of sums, for each week.  That is, start summing on the first false value in the vector, and when I get to true, produce the sum, and start summing again.
Is there a vector operation which can do this, without writing an explicit loop?
Thank you,
Dan Stanger
P.S. Sorry about the repost.
Eaton Vance Management
200 State Street
Boston, MA 02109
617 598 8261



More information about the R-help mailing list