Skip to content
Prev 369647 / 398503 Next

Determining which.max() within groups

cumsum() seems to be what you need.

This can probably be done more elegantly, but ...

out <- aggregate(Q ~ wyr, data = Daily, which.max)
tbl <- table(Daily$wyr)
out$Q <- out$Q + cumsum(c(0,tbl[-length(tbl)]))
out

## yields

   wyr  Q
1 1990  4
2 1991  6
3 1992  9
4 1993 15
5 1994 18

I leave the matter of Julian dates to you or others.

Cheers,
Bert




Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
On Tue, Jun 6, 2017 at 6:30 PM, Morway, Eric <emorway at usgs.gov> wrote: