conditional_values: Create a character column based on named conditions

View source: R/transforms_time.R

conditional_valuesR Documentation

Create a character column based on named conditions

Description

Create a character column based on named conditions

Usage

conditional_values(..., method = c("first", "last"), default = "",
  asfactor = F)

Arguments

...

Named arguments containing the conditions to evaluate

method

If multiple conditions are true which should supercede, the first or last one encountered

default

If no conditions are true, what value should be returned

asfactor

If TRUE, return a factor with the default value as the first level

Details

Named arguments are evaluated inside the function to produce logical values. The returned value (which will be a vector if the conditions return vectors) contains the names of the arguments that evaluate as TRUE. All conditions should evaluate to the same length and each position returns only one value. The returned value is either the first or last matched condition (selected by method) in the order provided, or the default value. This function is particularly useful for evaluating criteria in a data.frame using plyr or dplyr functions.

Value

A vector of the names of the conditions that evaluated to TRUE, according to the method.

Examples

DV = c(1,2,3,NA,"BQL","No Sample",4)
conditional_values(BADDV=!is.number(DV), BQL=DV=="BQL", MISSING=is.na(DV), default="OK", method="last")

qPharmetra/PMDatR documentation built on April 7, 2024, 5:42 p.m.