Perhaps you meant to point this out, but the cfs[which.max(cfs)] and cfs == ... are not the same:> x <- rep(1:2,3) > x[1] 1 2 1 2 1 2> x[which.max(x)][1] 2> x[x==max(x)][1] 2 2 2 So maybe your point is: which does the OP want (in case there are repeated maxes)? I suspect the == forms, but ...? Bert Gunter On Fri, Dec 3, 2021 at 2:56 PM Rui Barradas <ruipbarradas at sapo.pt> wrote:> > Hello, > > Inline. > > ?s 22:08 de 03/12/21, Rich Shepard escreveu: > > On Fri, 3 Dec 2021, Rich Shepard wrote: > > > >> I find solutions when the data_frame is grouped, but none when it's not. > > > > Thanks, Bert. ?which.max confirmed that's all I need to find the maximum > > value. > > > > Now I need to read more than ?filter to learn why I'm not getting the > > relevant row with: > >> which.max(pdx_disc$cfs) > > [1] 8054 > > This is the *index* for which cfs is the first maximum, not the maximum > value itself. > > > > >> filter(pdx_disc, cfs == 8054) > > Therefore, you probably want any of > > > filter(pdx_disc, cfs == cfs[8054]) > > filter(pdx_disc, cfs == cfs[which.max(cfs)]) > > filter(pdx_disc, cfs == max(cfs)) # I find this one better, simpler > > > Hope this helps, > > Rui Barradas > > > > # A tibble: 0 ? 9 > > # ? with 9 variables: site_nbr <chr>, year <int>, mon <int>, day <int>, > > # hr <dbl>, min <dbl>, tz <chr>, cfs <dbl>, sampdt <dttm> > > > > Regards, > > > > Rich > > > > ______________________________________________ > > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide > > http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
On Fri, 3 Dec 2021, Bert Gunter wrote:> Perhaps you meant to point this out, but the cfs[which.max(cfs)] and > cfs == ... are not the same: > >> x <- rep(1:2,3) >> x > [1] 1 2 1 2 1 2 >> x[which.max(x)] > [1] 2 >> x[x==max(x)] > [1] 2 2 2 > > So maybe your point is: which does the OP want (in case there are > repeated maxes)? I suspect the == forms, but ...?Bert, When I looked at the results I saw there were many rows with the maximum (and minimum) values. I thought those represented instrument limits, and they apparently do. For example, 99.9000 cubic feet per second is reached multiple times over the past 32 years.> max(pdx_disc$cfs)[1] 99900 and> filter(pdx_disc, cfs == max(cfs))# A tibble: 74 ? 9 site_nbr year mon day hr min tz cfs sampdt <chr> <int> <int> <int> <dbl> <dbl> <chr> <dbl> <dttm> 1 14211720 1988 11 28 0 0 PST 99900 1988-11-28 00:00:00 2 14211720 1988 11 28 5 0 PST 99900 1988-11-28 05:00:00 3 14211720 1988 11 28 5 10 PST 99900 1988-11-28 05:10:00 4 14211720 1988 11 28 5 20 PST 99900 1988-11-28 05:20:00 5 14211720 1988 11 29 6 20 PST 99900 1988-11-29 06:20:00 6 14211720 1988 11 29 13 0 PST 99900 1988-11-29 13:00:00 7 14211720 1988 11 29 13 10 PST 99900 1988-11-29 13:10:00 8 14211720 1988 11 29 15 20 PST 99900 1988-11-29 15:20:00 9 14211720 1989 1 11 0 0 PST 99900 1989-01-11 00:00:00 10 14211720 1989 1 11 0 10 PST 99900 1989-01-11 00:10:00 # ? with 64 more rows So the gauge was pegged at its top end quite a few times over the years. Makes me wonder just how much higher really was. Carpe weekend, Rich
Hello, You're right, I carelessly coded this. which.max returns the index to the first maximum of a vector, while the comparison of a vector with its max() returns an index to all vector elements. ?s 23:27 de 03/12/21, Bert Gunter escreveu:> Perhaps you meant to point this out, but the cfs[which.max(cfs)] and > cfs == ... are not the same: > >> x <- rep(1:2,3) >> x > [1] 1 2 1 2 1 2 >> x[which.max(x)] > [1] 2 >> x[x==max(x)] > [1] 2 2 2 > > So maybe your point is: which does the OP want (in case there are > repeated maxes)? I suspect the == forms, but ...? > > Bert Gunter > > On Fri, Dec 3, 2021 at 2:56 PM Rui Barradas <ruipbarradas at sapo.pt> wrote: >> >> Hello, >> >> Inline. >> >> ?s 22:08 de 03/12/21, Rich Shepard escreveu: >>> On Fri, 3 Dec 2021, Rich Shepard wrote: >>> >>>> I find solutions when the data_frame is grouped, but none when it's not. >>> >>> Thanks, Bert. ?which.max confirmed that's all I need to find the maximum >>> value. >>> >>> Now I need to read more than ?filter to learn why I'm not getting the >>> relevant row with: >>>> which.max(pdx_disc$cfs) >>> [1] 8054 >> >> This is the *index* for which cfs is the first maximum, not the maximum >> value itself. >> >>> >>>> filter(pdx_disc, cfs == 8054) >> >> Therefore, you probably want any ofShould be "one of", not "any of" Rui Barradas>> >> >> filter(pdx_disc, cfs == cfs[8054]) >> >> filter(pdx_disc, cfs == cfs[which.max(cfs)]) >> >> filter(pdx_disc, cfs == max(cfs)) # I find this one better, simpler >> >> >> Hope this helps, >> >> Rui Barradas >> >> >>> # A tibble: 0 ? 9 >>> # ? with 9 variables: site_nbr <chr>, year <int>, mon <int>, day <int>, >>> # hr <dbl>, min <dbl>, tz <chr>, cfs <dbl>, sampdt <dttm> >>> >>> Regards, >>> >>> Rich >>> >>> ______________________________________________ >>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >>> https://stat.ethz.ch/mailman/listinfo/r-help >>> PLEASE do read the posting guide >>> http://www.R-project.org/posting-guide.html >>> and provide commented, minimal, self-contained, reproducible code. >> >> ______________________________________________ >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code.