Group rows in ir objects by one or more variables
Usage
group_by.ir(
.data,
...,
.add = FALSE,
.drop = dplyr::group_by_drop_default(.data)
)
ungroup.ir(.data, ...)Arguments
- .data
An object of class
ir.- ...
In
group_by(), variables or computations to group by. Computations are always done on the ungrouped data frame. To perform computations on the grouped data, you need to use a separatemutate()step before thegroup_by(). Computations are not allowed innest_by(). Inungroup(), variables to remove from the grouping.- .add
When
FALSE, the default,group_by()will override existing groups. To add to the existing groups, use.add = TRUE.This argument was previously called
add, but that prevented creating a new grouping variable calledadd, and conflicts with our naming conventions.- .drop
Drop groups formed by factor levels that don't appear in the data? The default is
TRUEexcept when.datahas been previously grouped with.drop = FALSE. Seegroup_by_drop_default()for details.
See also
Other tidyverse:
arrange.ir(),
distinct.ir(),
extract.ir(),
filter-joins,
filter.ir(),
mutate,
mutate-joins,
nest,
pivot_longer.ir(),
pivot_wider.ir(),
rename,
rowwise.ir(),
select.ir(),
separate.ir(),
separate_rows.ir(),
slice,
summarize,
unite.ir()
Examples
## group_by
dplyr::group_by(ir_sample_data, sample_type)
#> # A tibble: 58 × 7
#> # Groups: sample_type [8]
#> id_measurement id_sample sample_type sample_comment klason_lignin
#> * <int> <chr> <chr> <chr> <units>
#> 1 1 GN 11-389 needles Abies Firma Momi fir 0.359944
#> 2 2 GN 11-400 needles Cupressocyparis leylandii… 0.339405
#> 3 3 GN 11-407 needles Juniperus chinensis Chine… 0.267552
#> 4 4 GN 11-411 needles Metasequoia glyptostroboi… 0.350016
#> 5 5 GN 11-416 needles Pinus strobus Torulosa 0.331100
#> 6 6 GN 11-419 needles Pseudolarix amabili Golde… 0.279360
#> 7 7 GN 11-422 needles Sequoia sempervirens Cali… 0.329672
#> 8 8 GN 11-423 needles Taxodium distichum Cascad… 0.356950
#> 9 9 GN 11-428 needles Thuja occidentalis Easter… 0.369360
#> 10 10 GN 11-434 needles Tsuga caroliniana Carolin… 0.289050
#> # ℹ 48 more rows
#> # ℹ 2 more variables: holocellulose <units>, spectra <named list>
## ungroup
dplyr::ungroup(dplyr::group_by(ir_sample_data, sample_type))
#> # A tibble: 58 × 7
#> id_measurement id_sample sample_type sample_comment klason_lignin
#> * <int> <chr> <chr> <chr> <units>
#> 1 1 GN 11-389 needles Abies Firma Momi fir 0.359944
#> 2 2 GN 11-400 needles Cupressocyparis leylandii… 0.339405
#> 3 3 GN 11-407 needles Juniperus chinensis Chine… 0.267552
#> 4 4 GN 11-411 needles Metasequoia glyptostroboi… 0.350016
#> 5 5 GN 11-416 needles Pinus strobus Torulosa 0.331100
#> 6 6 GN 11-419 needles Pseudolarix amabili Golde… 0.279360
#> 7 7 GN 11-422 needles Sequoia sempervirens Cali… 0.329672
#> 8 8 GN 11-423 needles Taxodium distichum Cascad… 0.356950
#> 9 9 GN 11-428 needles Thuja occidentalis Easter… 0.369360
#> 10 10 GN 11-434 needles Tsuga caroliniana Carolin… 0.289050
#> # ℹ 48 more rows
#> # ℹ 2 more variables: holocellulose <units>, spectra <named list>