censorData: Censoring data

Description Usage Arguments Value Examples

View source: R/utilities-data-validation.R

Description

For numeric types, checks if x is in rng = (min, max) and censors values to either min or max if it is out of the range. For categorical types, values not in 'levels' are coded NA.

Usage

1
censorData(x, varType, rng = NULL, levels = NULL, rngFormat = NULL)

Arguments

x

A vector of numeric or categorial values to censor.

varType

Character indicating the variable type of x. Possible values include: numeric, logical, ...

rng

For x that is a numeric vector, a vector (min, max) of the bounds of the range. For input x that is a numeric matrices or dataframe with n columns, a list of (min, max) bounds of length n.

levels

For categorical types, a vector containing the levels to be returned.

rngFormat

For numeric types, a string describing the format of the range input. One of either 'vector' for x that is a numeric vector and rng that is a (min, max) tuple, or 'list' for x that is a numeric matrix or dataframe with n columns and rng that is a list of (min, max) bounds of length n.

Value

Original vector with values outside the bounds censored to the bounds.

Examples

1
2
censorData(x=1:10, varType='integer', rng=c(2.5, 7))
censorData(x=c('a', 'b', 'c', 'd'), varType='character', levels=c('a', 'b', 'c'))

IQSS/PSI-Library documentation built on Feb. 15, 2020, 9:03 p.m.