Usage
summ(
.data,
...,
.by = NULL,
.keep_all = FALSE,
.detail = FALSE,
.stat = character(0)
)
tabstat(
.data,
...,
.by = NULL,
.keep_all = FALSE,
.detail = FALSE,
.stat = "mean"
)
Arguments
- .data
A data frame, data frame extension (e.g. a tibble), or a lazy data frame (e.g. from dbplyr or dtplyr).
- ...
<
tidy-select
> or <data-masking
> Variables to tabulate.Both tidyselect (e.g.,
starts_with()
) and data masking (e.g.,x_sq = x^2
) are supported. See examples below.- .by
-
<
tidy-select
> Optionally, a selection of columns to group by for just this operation, functioning as an alternative togroup_by()
. For details and examples, see ?dplyr_by. - .keep_all
A logical. If
TRUE
, all variables are kept.- .detail
A logical. If
TRUE
, the detailed summary is returned.- .stat
A character vector. If specified, only the listed statistics are returned.
Examples
summ(lifeexp)
#> Warning: country is non-numeric and thus removed.
#> Warning: region is a labelled variable (*).
#> # A tibble: 5 × 8
#> name type n unique min mean sd max
#> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 *region dbl+lbl 68 3 1 1.5 0.743 3
#> 2 popgrowth dbl 68 30 -0.5 0.972 0.931 3
#> 3 lexp dbl 68 18 54 72.3 4.72 79
#> 4 gnppc dbl 63 62 370 8675. 10635. 39980
#> 5 safewater dbl 40 29 28 76.1 17.9 100
summ(lifeexp, .by = region)
#> Warning: country is non-numeric and thus removed.
#> # A tibble: 12 × 9
#> region name type n unique min mean sd max
#> <hvn_lbll> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 1 popgrowth dbl 44 20 -0.5 0.525 0.718 2.80
#> 2 1 lexp dbl 44 15 65 73.1 4.15 79
#> 3 1 gnppc dbl 41 40 370 10738. 11794. 39980
#> 4 1 safewater dbl 17 12 55 79.8 18.6 100
#> 5 2 popgrowth dbl 14 10 0.700 1.69 0.749 3
#> 6 2 lexp dbl 14 12 54 71.2 6.41 79
#> 7 2 gnppc dbl 12 12 410 5817. 8929. 29240
#> 8 2 safewater dbl 13 13 28 75 19.2 99
#> 9 3 popgrowth dbl 10 8 0.700 1.93 0.617 2.90
#> 10 3 lexp dbl 10 7 62 70.3 3.83 75
#> 11 3 gnppc dbl 10 10 1010 3645 2255. 8030
#> 12 3 safewater dbl 10 10 39 71.2 15.0 89
tabstat(lifeexp, .by = region)
#> Warning: country is non-numeric and thus removed.
#> # A tibble: 12 × 4
#> region name type mean
#> <hvn_lbll> <chr> <chr> <dbl>
#> 1 1 popgrowth dbl 0.525
#> 2 1 lexp dbl 73.1
#> 3 1 gnppc dbl 10738.
#> 4 1 safewater dbl 79.8
#> 5 2 popgrowth dbl 1.69
#> 6 2 lexp dbl 71.2
#> 7 2 gnppc dbl 5817.
#> 8 2 safewater dbl 75
#> 9 3 popgrowth dbl 1.93
#> 10 3 lexp dbl 70.3
#> 11 3 gnppc dbl 3645
#> 12 3 safewater dbl 71.2
lifeexp %>%
summ(
dplyr::where(is.numeric),
.by = region,
.stat = c("mean", "sd")
)
#> # A tibble: 12 × 5
#> region name type mean sd
#> <hvn_lbll> <chr> <chr> <dbl> <dbl>
#> 1 1 popgrowth dbl 0.525 0.718
#> 2 1 lexp dbl 73.1 4.15
#> 3 1 gnppc dbl 10738. 11794.
#> 4 1 safewater dbl 79.8 18.6
#> 5 2 popgrowth dbl 1.69 0.749
#> 6 2 lexp dbl 71.2 6.41
#> 7 2 gnppc dbl 5817. 8929.
#> 8 2 safewater dbl 75 19.2
#> 9 3 popgrowth dbl 1.93 0.617
#> 10 3 lexp dbl 70.3 3.83
#> 11 3 gnppc dbl 3645 2255.
#> 12 3 safewater dbl 71.2 15.0