Merck / metalite.ae

An R package for standard adverse events analysis
http://merck.github.io/metalite.ae/
GNU General Public License v3.0
17 stars 4 forks source link

correct the way to assign levels attribute for observation dataset #179

Closed wangben718 closed 10 months ago

wangben718 commented 10 months ago

bug fix:

forestly_adsl_mod <- forestly_adsl |>
  dplyr::mutate(
    TRT01A = ifelse(USUBJID == "01-718-1355", "", TRT01A),
    TRTA = factor(TRT01A, levels = c("Xanomeline Low Dose", "Placebo"), labels = c("Low Dose", "Placebo"))
  )
forestly_adae_mod <- forestly_adae |>
  dplyr::filter(USUBJID != "01-718-1355")
factor(forestly_adae_mod$TRTA, levels = forestly_adsl_mod$TRTA)

This approach will make "Xanomeline Low Dose" to NA since "Low Dose" could not be found in forestly_adae_mod$TRTA as input of factor().

forestly_adae_mod$TRTA <- factor(forestly_adae_mod$TRTA, levels(forestly_adsl_mod$TRTA))
levels(forestly_adae_mod$TRTA) <- levels(forestly_adsl_mod$TRTA)

This approach works well.