Summarize each group in a ir object to fewer rows
Arguments
- .data
An object of class
ir.- ...
<
data-masking> Name-value pairs of summary functions. The name will be the name of the variable in the result.The value can be:
A vector of length 1, e.g.
min(x),n(), orsum(is.na(y)).A data frame, to add multiple columns from a single expression.
Returning values with size 0 or >1 was deprecated as of 1.1.0. Please use
reframe()for this instead.- .groups
Grouping structure of the result.
"drop_last": dropping the last level of grouping. This was the only supported option before version 1.0.0.
"drop": All levels of grouping are dropped.
"keep": Same grouping structure as
.data."rowwise": Each row is its own group.
When
.groupsis not specified, it is chosen based on the number of rows of the results:If all the results have 1 row, you get "drop_last".
If the number of rows varies, you get "keep" (note that returning a variable number of rows was deprecated in favor of
reframe(), which also unconditionally drops all levels of grouping).
In addition, a message informs you of that choice, unless the result is ungrouped, the option "dplyr.summarise.inform" is set to
FALSE, or whensummarise()is called from a function in a package.
Value
.data with summarized columns. If the spectra column is dropped
or invalidated (see ir_new_ir()), the ir class is dropped, else the
object is of class ir.
See also
Other tidyverse:
arrange.ir(),
distinct.ir(),
extract.ir(),
filter-joins,
filter.ir(),
group_by,
mutate,
mutate-joins,
nest,
pivot_longer.ir(),
pivot_wider.ir(),
rename,
rowwise.ir(),
select.ir(),
separate.ir(),
separate_rows.ir(),
slice,
unite.ir()
Examples
## summarize
# select in each sample_type groups the first spectrum
ir_sample_data |>
dplyr::group_by(sample_type) |>
dplyr::summarize(spectra = spectra[[1]])
#> Warning: Returning more (or less) than 1 row per `summarise()` group was deprecated in
#> dplyr 1.1.0.
#> ℹ Please use `reframe()` instead.
#> ℹ When switching from `summarise()` to `reframe()`, remember that `reframe()`
#> always returns an ungrouped data frame and adjust accordingly.
#> `summarise()` has grouped output by 'sample_type'. You can override using the
#> `.groups` argument.
#> # A tibble: 26,808 × 2
#> # Groups: sample_type [8]
#> sample_type spectra$x $y
#> * <chr> <int> <dbl>
#> 1 hardwood 4000 0.000193
#> 2 hardwood 3999 0.000214
#> 3 hardwood 3998 0.000179
#> 4 hardwood 3997 0.000106
#> 5 hardwood 3996 0.0000386
#> 6 hardwood 3995 0.0000354
#> 7 hardwood 3994 0.000102
#> 8 hardwood 3993 0.000210
#> 9 hardwood 3992 0.000294
#> 10 hardwood 3991 0.000312
#> # ℹ 26,798 more rows