get_bins {YEAB} | R Documentation |
A function to binarize a numeric vector with a given resolution
Description
A function to binarize a numeric vector with a given resolution
Usage
get_bins(x, x_min, x_max, res)
Arguments
x |
numeric, the vector to be binarized |
x_min |
numeric, the min value of a vector to create the bins (e.g., 0) |
x_max |
numeric, the maximum value of the vector x to binarize |
res |
numeric, the resolution; if x is time, res can be 1 s |
Value
the vector of bins for which x is in
Examples
x <- 1:20
get_bins(x, 0, 20, 5)
# Returns
# [1] 5 5 5 5 5 10 10 10 10 10 15 15 15 15 15 20 20 20 20 20
# set.seed(10)
x <- runif(20, 0, 10)
get_bins(x, 0, 10, 0.5)
# Returns
# 1] 5.5 3.5 4.5 7.0 1.0 2.5 3.0 3.0 6.5 4.5 7.0 6.0 1.5 6.0 4.0 4.5 1.0 3.0 4.0 8.5
[Package YEAB version 1.0.6 Index]