AssignBins: Assign bin numbers to a vector

Description Usage Arguments Value Examples

Description

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.

Usage

1
AssignBins(xs, bin_width = 3, na_location = "tail", partial = FALSE)

Arguments

xs

a vector

bin_width

the number of items to put in each bin. Default is 3.

na_location

Where to assign NA bin numbers. "head" and "tail" respectively put the NA elements at the head and tail of the vector; "split" alternates between "tail" and "head".

partial

whether to exclude values that don't fit evenly into bins. Defaults to FALSE, so that the user is warned if a bin is incomplete.

Value

a vector of bin-numbers. If bin_width does not evenly divide xs, the remainder elements are given a bin number of NA.

Examples

1
2
3
4
5
6
7
8
AssignBins(1:14, bin_width = 3, "head")
# [1] NA NA  1  1  1  2  2  2  3  3  3  4  4  4
AssignBins(1:14, bin_width = 3, "tail")
# [1]  1  1  1  2  2  2  3  3  3  4  4  4 NA NA
AssignBins(1:7, bin_width = 5, "split")
# [1] NA  1  1  1  1  1 NA
AssignBins(1:8, bin_width = 5, "split")
# [1] NA  1  1  1  1  1 NA NA

tjmahr/lookr documentation built on May 31, 2019, 3:41 p.m.