Learn R Programming

dbplot (version 0.3.3)

db_bin: Bin formula

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

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

Run this code
# NOT RUN {
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()
# }

Run the code above in your browser using DataLab