[R] Find tibble row with maximum recorded value

Rui Barradas ru|pb@rr@d@@ @end|ng |rom @@po@pt
Fri Dec 3 23:56:21 CET 2021


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 using 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.



More information about the R-help mailing list