Related Variables: Assign
rel_var.Rd
Assign values to a related variable within a domain.
Arguments
- df
(
data.frame
)
Data frame containing the related variables.- var_name
(
character
)
Name of variable related torel_var
to add todf
.- related_var
(
character
)
Name of variable withindf
with values to which values ofvar_name
must relate.- var_values
(
any
)
Vector of values related to values ofrelated_var
.
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
)
)
random.cdisc.data:::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
)
)
random.cdisc.data:::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