Description Usage Arguments Value Examples
The first step in binning/down-sampling some data is assigning items to bins. This function takes a vector and a bin size and returns the bin assignments.
1 | assign_bins_vec(xs, bin_width = 3, na_location = "tail", partial = FALSE)
|
xs |
a vector |
bin_width |
the number of items to put in each bin. Default is 3. |
na_location |
Where to assign |
partial |
whether to exclude values that don't fit evenly into bins.
Defaults to |
a vector of bin-numbers. If bin_width
does not evenly divide
xs
, the remainder elements are given a bin number of NA
.
1 2 3 4 5 6 7 8 | assign_bins_vec(1:14, bin_width = 3, "head")
# [1] NA NA 1 1 1 2 2 2 3 3 3 4 4 4
assign_bins_vec(1:14, bin_width = 3, "tail")
# [1] 1 1 1 2 2 2 3 3 3 4 4 4 NA NA
assign_bins_vec(1:7, bin_width = 5, "split")
# [1] NA 1 1 1 1 1 NA
assign_bins_vec(1:8, bin_width = 5, "split")
# [1] NA 1 1 1 1 1 NA NA
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.