[R] Find tibble row with maximum recorded value

Jeff Newmiller jdnewm|| @end|ng |rom dcn@d@v|@@c@@u@
Fri Dec 3 22:46:27 CET 2021


cfs is not a function. Don't put parentheses next to it. Use square brackets for indexing.

On December 3, 2021 12:55:34 PM PST, Rich Shepard <rshepard using appl-ecosys.com> wrote:
>I find solutions when the data_frame is grouped, but none when it's not.
>
>The data:
># A tibble: 813,693 × 9
>    site_nbr  year   mon   day    hr   min tz      cfs sampdt
>    <chr>    <int> <int> <int> <dbl> <dbl> <chr> <dbl> <dttm>
>  1 14211720  1988    10     1     0    10 PDT   16800 1988-10-01 00:10:00
>  2 14211720  1988    10     1     0    20 PDT   16800 1988-10-01 00:20:00
>  3 14211720  1988    10     1     0    30 PDT   17300 1988-10-01 00:30:00
>  4 14211720  1988    10     1     0    40 PDT   18200 1988-10-01 00:40:00
>  5 14211720  1988    10     1     0    50 PDT   18100 1988-10-01 00:50:00
>  6 14211720  1988    10     1     1     0 PDT   18400 1988-10-01 01:00:00
>  7 14211720  1988    10     1     1    10 PDT   18700 1988-10-01 01:10:00
>  8 14211720  1988    10     1     1    20 PDT   19200 1988-10-01 01:20:00
>  9 14211720  1988    10     1     1    30 PDT   19200 1988-10-01 01:30:00
>10 14211720  1988    10     1     1    40 PDT   18900 1988-10-01 01:40:00
># … with 813,683 more rows
>
>The script:
>library(tidyverse)
>
>max_pdx_disc <- pdx_disc %>%
>     summarize(max_cfs = max(cfs), max_cfs_sampdt = cfs(which.max(cfs)))
>
>The error:
>> source('../scripts/filter_by_column_max.r') 
>Error: Problem with `summarise()` column `max_cfs_sampdt`.
>  `max_cfs_sampdt = sampt(which.max(cfs))`.
>  could not find function "sampt"
>> Run `rlang::last_error()` to see where the error occurred.
>
>I looked at the the last_error and the traceback without understanding how
>to filter the row with the maximum cfs value.
>
>What do I read to learn how to return this row?
>
>TIA,
>
>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.

-- 
Sent from my phone. Please excuse my brevity.



More information about the R-help mailing list