View source: R/transforms_time.R
conditional_values | R Documentation |
Create a character column based on named conditions
conditional_values(..., method = c("first", "last"), default = "",
asfactor = F)
... |
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 |
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.
A vector of the names of the conditions that evaluated to TRUE, according to the method.
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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.