Skip to contents

condition_add() tags records in a data set, indicating which rows match the specified conditions, resulting in a conditioned data frame. Learn how to integrate conditioned data frames in your SDTM domain derivation in vignette("cnd_df").

Usage

condition_add(dat, ..., .na = NA, .dat2 = rlang::env())

Arguments

dat

A data frame.

...

Conditions to filter the data frame.

.na

Return value to be used when the conditions evaluate to NA.

.dat2

An optional environment to look for variables involved in logical expression passed in .... A data frame or a list can also be passed that will be coerced to an environment internally.

Value

A conditioned data frame, meaning a tibble with an additional class cnd_df and a logical vector attribute indicating matching rows.

Examples

(df <- tibble::tibble(x = 1L:3L, y = letters[x]))
#> # A tibble: 3 × 2
#>       x y    
#>   <int> <chr>
#> 1     1 a    
#> 2     2 b    
#> 3     3 c    

# Mark rows for which `x` greater than `1`
(cnd_df <- condition_add(dat = df, x > 1L))
#> # A tibble:  3 × 2
#> # Cond. tbl: 2/1/0
#>         x y    
#>     <int> <chr>
#> 1 F     1 a    
#> 2 T     2 b    
#> 3 T     3 c