The user passes a data set to modify, a yspec object, and the names of flags in the yspec object to create factors in the data set using ys_factors().

ys_factors_fl(data, spec, ...)

Arguments

data

the data set to modify.

spec

a yspec object.

...

tidy-select specification of flag names to select.

Details

Only eligible columns will be considered for factor creation (either a values field is present or the make_factor flag is set). Therefore, a flag containing a general list of data columns (potentially continuous and discrete) could be passed without generating an error.

Examples

data <- ys_help$data()
spec <- ys_help$spec()

names(ys_flags(spec))
#> [1] "covariate" "nm"        "times"     "cat"      

data <- ys_factors_fl(data, spec, cat)

head(data, 2)
#>    C NUM ID SUBJ TIME         SEQ CMT EVID AMT     DV   AGE    WT   CRCL ALB
#> 1 NA   1  1    1 0.00 observation   1    1   5  0.000 28.03 55.16 114.45 4.4
#> 2 NA   2  1    1 0.61        dose   2    0  NA 61.005 28.03 55.16 114.45 4.4
#>     BMI    AAG  SCR   AST   ALT     HT CP TAFD  TAD LDOS MDV BLQ PHASE STUDY
#> 1 21.67 106.36 1.14 11.88 12.66 159.55  0 0.00 0.00    5   1   0     1   SAD
#> 2 21.67 106.36 1.14 11.88 12.66 159.55  0 0.61 0.61    5   0   0     1   SAD
#>     RF SEQ_v STUDY_v
#> 1 norm     0       1
#> 2 norm     1       1

data <- ys_factors_fl(data, spec, covariate, nm)

head(data, 2)
#>    C NUM ID SUBJ TIME         SEQ CMT EVID AMT     DV   AGE    WT   CRCL ALB
#> 1 NA   1  1    1 0.00 observation   1    1   5  0.000 28.03 55.16 114.45 4.4
#> 2 NA   2  1    1 0.61        dose   2    0  NA 61.005 28.03 55.16 114.45 4.4
#>     BMI    AAG  SCR   AST   ALT     HT CP TAFD  TAD LDOS         MDV BLQ PHASE
#> 1 21.67 106.36 1.14 11.88 12.66 159.55  0 0.00 0.00    5     missing   0     1
#> 2 21.67 106.36 1.14 11.88 12.66 159.55  0 0.61 0.61    5 non-missing   0     1
#>   STUDY   RF SEQ_v STUDY_v MDV_v
#> 1   SAD norm     0       1     1
#> 2   SAD norm     1       1     0