bin_vector: Snap continuous values to a grid

View source: R/bin_vector.R

bin_vectorR Documentation

Snap continuous values to a grid

Description

This function bins a continuously valued vector based on user-defined bins. It is useful for binning continuously valued genotypes. Each value in the matrix gets shifted to the nearest provided in the argument bins.

Usage

bin_vector(vectorX, bins = seq(0, 1, 0.5))

Arguments

vectorX

A vector of numeric values to bin

bins

A vector of values to snap the values in vectorX to.

Value

A vector the same length as vectorX in which each value in vectorX has been sent to the nearest value in bins. For example, if bins is c(0, 0.5, 1), and vectorX contains a 0.49. That 0.49 value will be sent to 0.5. The returned vector contains only the values specified in bins.


cape documentation built on May 29, 2024, 5:11 a.m.