Skip to content

Commit 5477d8a

Browse files
committed
helper for cutting bins
1 parent 9702e92 commit 5477d8a

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

R/bin.R

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,7 @@ bin_vector <- function(x, bins, weight = NULL, pad = FALSE) {
176176
weight[is.na(weight)] <- 0
177177
}
178178

179-
bin_idx <- cut(x, bins$fuzzy, right = bins$right_closed,
180-
include.lowest = TRUE)
179+
bin_idx <- bin_cut(x, bins)
181180
bin_count <- as.numeric(tapply(weight, bin_idx, sum, na.rm = TRUE))
182181
bin_count[is.na(bin_count)] <- 0
183182

@@ -205,6 +204,10 @@ bin_vector <- function(x, bins, weight = NULL, pad = FALSE) {
205204
bin_out(bin_count, bin_x, bin_widths)
206205
}
207206

207+
bin_cut <- function(x, bins) {
208+
cut(x, bins$fuzzy, right = bins$right_closed, include.lowest = TRUE)
209+
}
210+
208211
bin_out <- function(count = integer(0), x = numeric(0), width = numeric(0),
209212
xmin = x - width / 2, xmax = x + width / 2) {
210213
density <- count / width / sum(abs(count))

0 commit comments

Comments
 (0)