Create one or more scalar variables summarizing the variables of an existing data.table.

summarise(.data, ..., by = NULL)

summarise_when(.data, when, ..., by = NULL)

summarise_vars(.data, .cols = NULL, .func, ..., by)

Arguments

.data

A data.table

...

List of variables or name-value pairs of summary/modifications functions for summarise_dt.Additional parameters to be passed to parameter '.func' in summarise_vars.

by

Unquoted name of grouping variable of list of unquoted names of grouping variables. For details see data.table

when

An object which can be coerced to logical mode

.cols

Columns to be summarised.

.func

Function to be run within each column, should return a value or vectors with same length.

Value

A data.table

Examples


a = as.data.table(iris)
a %>% summarise(sum = sum(Sepal.Length),avg = mean(Sepal.Length))
#>      sum      avg
#>    <num>    <num>
#> 1: 876.5 5.843333


a %>%
  summarise_when(Sepal.Length > 5, avg = mean(Sepal.Length), by = Species)
#>       Species      avg
#>        <fctr>    <num>
#> 1:     setosa 5.313636
#> 2: versicolor 5.997872
#> 3:  virginica 6.622449

a %>%
  summarise_vars(is.numeric, min, by = Species)
#>       Species Sepal.Length Sepal.Width Petal.Length Petal.Width
#>        <fctr>        <num>       <num>        <num>       <num>
#> 1:     setosa          4.3         2.3          1.0         0.1
#> 2: versicolor          4.9         2.0          3.0         1.0
#> 3:  virginica          4.9         2.2          4.5         1.4