This funciton is a generic that includes support for dataframes and lists of
dataframes. For dataframes, this function is a shortcut to
dplyr::summarize(data, min = min(x), max = max(x))
. For lists of dataframes
that idea applies applies to each element of the list.
Arguments
- data
A dataframe or a list of dataframes.
- col
Unquoted expression giving the name of a column in
data
.- .by
A vector or list of vectors depending on whether
data
is a dataframe or list of dataframes, respective. For details see.by
indplyr::summarize()
.- na.rm
a logical indicating whether missing values should be removed.
Value
A dataframe or a list of dataframes:
The rows come from the underlying groups.
The columns come from the grouping keys plus the new columns
min
andmax
.The groups are dropped.
See also
Other helpers:
exclude()
,
jitter_range()
,
join_to()
,
unnest_product()
Examples
library(tibble)
data <- tibble(x = 1:4, group = letters[c(1, 1, 2, 2)])
data
#> # A tibble: 4 × 2
#> x group
#> <int> <chr>
#> 1 1 a
#> 2 2 a
#> 3 3 b
#> 4 4 b
summarize_range(data, "x", .by = "group")
#> # A tibble: 2 × 3
#> group min max
#> <chr> <int> <int>
#> 1 a 1 2
#> 2 b 3 4
list <- split(data, data$group)
list
#> $a
#> # A tibble: 2 × 2
#> x group
#> <int> <chr>
#> 1 1 a
#> 2 2 a
#>
#> $b
#> # A tibble: 2 × 2
#> x group
#> <int> <chr>
#> 1 3 b
#> 2 4 b
#>
summarize_range(list, col = "x", .by = list(a = "group", b = "group"))
#> $a
#> # A tibble: 1 × 3
#> group min max
#> <chr> <int> <int>
#> 1 a 1 2
#>
#> $b
#> # A tibble: 1 × 3
#> group min max
#> <chr> <int> <int>
#> 1 b 3 4
#>