db_bin: Bin formula

Description Usage Arguments Examples

View source: R/dbbin.R

Description

Uses the rlang package to build the formula needed to create the bins of a numeric variable in an unevaluated fashion. This way, the formula can be then passed inside a dplyr verb.

Usage

1
db_bin(var, bins = 30, binwidth = NULL)

Arguments

var

Variable name or formula

bins

Number of bins. Defaults to 30.

binwidth

Single value that sets the side of the bins, it overrides bins

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
library(dplyr)

# Important: Always name the field and
# prefix the function with `!!`` (See Details)

# Uses the default 30 bins
mtcars %>%
  group_by(x = !!db_bin(mpg)) %>%
  tally()

# Uses binwidth which overrides bins
mtcars %>%
  group_by(x = !!db_bin(mpg, binwidth = 10)) %>%
  tally()

dbplot documentation built on Feb. 7, 2020, 9:06 a.m.