---
title: "tidybins"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{tidybins}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```
```{r setup}
library(tidybins)
suppressPackageStartupMessages(library(dplyr))
```
# Bin Value
Binning by value is the only original binning method implemented in this package. It is inspired by the case in marketing when accounts need to be binned by their sales. For example, creating 10 bins, where each bin represent 10% of all market sales. The first bin contains the highest sales accounts, thus has the small total number of accounts, whereas the last bin contains the smallest sales accounts, thus requiring the most number of accounts per bin to reach 10% of the market sales.
```{r}
tibble::tibble(SALES = as.integer(rnorm(1000L, mean = 10000L, sd = 3000))) -> sales_data
sales_data %>%
bin_cols(SALES, bin_type = "value") -> sales_data1
sales_data1
```
Notice that the sum is equal across bins.
```{r}
sales_data1 %>%
bin_summary() %>%
print(width = Inf)
```