Skip to contents

Create AVAL from AVALC by calling a function provided by the user. If calling the function fails, the error is caught and a helpful error message provided.

Usage

call_aval_fun(dataset, aval_fun)

Arguments

dataset

Input dataset

The variable AVALC is expected.

Permitted Values: a dataframe

aval_fun

Function returning the AVALC values

The specified function must expect one argument expecting a character vector and must return a numeric vector.

Permitted Values: a function

Value

The input dataset with AVAL added

Details

The new variable AVAL is set to aval_fun(AVALC).

Author

Stefan Bundfuss

Examples


library(tibble)
library(dplyr)
#> 
#> Attaching package: ‘dplyr’
#> The following objects are masked from ‘package:stats’:
#> 
#>     filter, lag
#> The following objects are masked from ‘package:base’:
#> 
#>     intersect, setdiff, setequal, union

data <- tribble(
  ~AVALC,
  "YES",
  "NO"
)

yn_map <- function(x) {
  case_when(
    x == "YES" ~ 1,
    x == "NO" ~ 0
  )
}

call_aval_fun(
  data,
  yn_map
)
#> # A tibble: 2 x 2
#>   AVALC  AVAL
#>   <chr> <dbl>
#> 1 YES       1
#> 2 NO        0