loop_summarise: Summarise in loop

Description Usage Arguments Value Examples

View source: R/loop-summarise.R

Description

Summarise in loop

Usage

1
2
3
loop_summarise(.data, .x, ...)

loop_summarize(.data, .x, ...)

Arguments

.data

a data.frame-like object

.x

a vector the function is looping on

...

Name-value pairs of summary functions. The name will be the name of the variable in the result. The value can be:

  • A vector of length 1, e.g. min(x), n(), or sum(is.na(y)).

  • A vector of length n, e.g. quantile().

  • A data frame, to add multiple columns from a single expression.

Value

An object of tibble class It combines multiple summaries performed on the input data.frame.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
suppressMessages(library(dplyr))
suppressMessages(library(glue))
quantiles <- c(0.25, 0.50, 0.75)
iris %>%
  group_by(Species) %>%
  loop_summarise(
      quantiles,
      glue("Petal.Length.{.x}") := quantile(Petal.Length, .x),
      glue("Petal.Width.{.x}") := quantile(Petal.Width, .x)
  )

krzjoa/looplyr documentation built on Oct. 30, 2020, 2:22 a.m.