bin_vector: bin a numeric vector and return a factor of bins

bin_vectorR Documentation

bin a numeric vector and return a factor of bins

Description

bin a numeric vector and return a factor of bins

Usage

bin_vector(numeric_vector, breaks = 10, binLabels = NULL, return_df = TRUE)

Arguments

numeric_vector
breaks

either a single number specifying the number of equally widthed breaks, or a vector of break boundaries

binLabels

optional labels for the new bins that are returned instead of the bin range

return_df

return a data.frame with boundaries, the value and the bin level

Examples

vec = sample(1:100, size = 100)
bin_vector(vec, breaks = 10)
bin_vector(vec, breaks = c(0, 33, 66, 100))
bin_vector(vec, breaks = c(0, 33, 66, 100), 
           binLabels = c('lower tertile', 'middle tertile', 'upper tertile'),
           return_df = FALSE)

mathosi/jj documentation built on Feb. 25, 2024, 2:29 p.m.