summarise: Summarise multiple values to a single value.

Description Usage Arguments Value Backend variations See Also Examples

View source: R/manip.r

Description

Summarise multiple values to a single value.

Usage

1
2
3
4
5
6
7
summarise(.data, ...)

summarise_(.data, ..., .dots)

summarize(.data, ...)

summarize_(.data, ..., .dots)

Arguments

.data

A tbl. All main verbs are S3 generics and provide methods for tbl_df, tbl_dt and tbl_sql.

...

Name-value pairs of summary functions like min(), mean(), max() etc.

.dots

Used to work around non-standard evaluation. See vignette("nse") for details.

Value

An object of the same class as .data. One grouping level will be dropped.

Data frame row names are silently dropped. To preserve, convert to an explicit variable.

Backend variations

Data frames are the only backend that supports creating a variable and using it in the same summary. See examples for more details.

See Also

Other single.table.verbs: arrange, filter, mutate, select, slice

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
summarise(mtcars, mean(disp))
summarise(group_by(mtcars, cyl), mean(disp))
summarise(group_by(mtcars, cyl), m = mean(disp), sd = sd(disp))

# With data frames, you can create and immediately use summaries
by_cyl <- mtcars %>% group_by(cyl)
by_cyl %>% summarise(a = n(), b = a + 1)

## Not run: 
# You can't with data tables or databases
by_cyl_dt <- mtcars %>% dtplyr::tbl_dt() %>% group_by(cyl)
by_cyl_dt %>% summarise(a = n(), b = a + 1)

by_cyl_db <- src_sqlite(":memory:", create = TRUE) %>%
  copy_to(mtcars) %>% group_by(cyl)
by_cyl_db %>% summarise(a = n(), b = a + 1)

## End(Not run)

sctyner/dplyr050 documentation built on May 17, 2019, 2:22 p.m.