[R] Find tibble row with maximum recorded value
Rich Shepard
r@hep@rd @end|ng |rom @pp|-eco@y@@com
Fri Dec 3 21:55:34 CET 2021
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
More information about the R-help
mailing list