Re: [R] Determining which.max() within groups

2017-06-07 Thread Charles C. Berry
On Tue, 6 Jun 2017, Morway, Eric wrote: Using the dataset below, I got close to what I'm after, but not quite all the way there. Any suggestions appreciated: Daily <- read.table(textConnection(" Date wyrQ 1911-04-01 1990 4.530695 1911-04-02 1990 4.700596 1911-04-03 1990 4.898814 1

Re: [R] Determining which.max() within groups

2017-06-07 Thread Jeff Newmiller
Aggregate can do both which.max and group length calculations, but the result ends up as a matrix inside the data frame, which I find cumbersome to work with. Daily <- read.table( text = " Date wyrQ 1911-04-01 1990 4.530695 1911-04-02 1990 4.700596 1911-04-03 1990 4.898814 1911-04-

Re: [R] Determining which.max() within groups

2017-06-07 Thread David L Carlson
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Bert Gunter Sent: Tuesday, June 6, 2017 9:16 PM To: Morway, Eric Cc: R mailing list Subject: Re: [R] Determining which.max() within groups cumsum() seems to be what you need. This can probably be done more elegantly, but ... out <- ag

Re: [R] Determining which.max() within groups

2017-06-06 Thread Bert Gunter
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

[R] Determining which.max() within groups

2017-06-06 Thread Morway, Eric
Using the dataset below, I got close to what I'm after, but not quite all the way there. Any suggestions appreciated: Daily <- read.table(textConnection(" Date wyrQ 1911-04-01 1990 4.530695 1911-04-02 1990 4.700596 1911-04-03 1990 4.898814 1911-04-04 1990 5.097032 1911-04-05 1991 5.2