Assign values to a related variable within a domain.
Examples
# Example with data.frame.
params <- c("Level A", "Level B", "Level C")
adlb_df <- data.frame(
ID = 1:9,
PARAM = factor(
rep(c("Level A", "Level B", "Level C"), 3),
levels = params
)
)
rel_var(
df = adlb_df,
var_name = "PARAMCD",
var_values = c("A", "B", "C"),
related_var = "PARAM"
)
#> ID PARAM PARAMCD
#> 1 1 Level A A
#> 2 2 Level B B
#> 3 3 Level C C
#> 4 4 Level A A
#> 5 5 Level B B
#> 6 6 Level C C
#> 7 7 Level A A
#> 8 8 Level B B
#> 9 9 Level C C
# Example with tibble.
adlb_tbl <- tibble::tibble(
ID = 1:9,
PARAM = factor(
rep(c("Level A", "Level B", "Level C"), 3),
levels = params
)
)
rel_var(
df = adlb_tbl,
var_name = "PARAMCD",
var_values = c("A", "B", "C"),
related_var = "PARAM"
)
#> # A tibble: 9 × 3
#> ID PARAM PARAMCD
#> <int> <fct> <fct>
#> 1 1 Level A A
#> 2 2 Level B B
#> 3 3 Level C C
#> 4 4 Level A A
#> 5 5 Level B B
#> 6 6 Level C C
#> 7 7 Level A A
#> 8 8 Level B B
#> 9 9 Level C C