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.
Arguments
- dataset
Input dataset
The variable
AVALC
is expected.Permitted Values: a dataframe
- aval_fun
Function returning the
AVALC
valuesThe specified function must expect one argument expecting a character vector and must return a numeric vector.
Permitted Values: a function
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