Issue while making summary - non corresponding categories are coming in categorical analysis #1286
-
Want to remove all the rows with complete 0 which occur while generating the summary can Add trim_rows() at the end but if a sub-group is not present in group it should not appear. adae <- adae %>%
filter(AESOC %in% c('CARDIAC DISORDERS', 'EYE DISORDERS')) %>%
select(USUBJID, TRTA, AESOC, AETERM) %>%
mutate(AETERM = factor(AETERM))
basic_table(title = "Demo table", main_footer = "Notes") %>%
split_cols_by("TRTA") %>%
add_colcounts() %>%
split_rows_by("AESOC", split_label = "AESOC", label_pos = "topleft") %>%
analyze_vars(vars = "AETERM", .stats = "count_fraction", .labels = "hello", na.rm = TRUE) %>%
rtables::append_topleft(" n (%)") %>%
build_table(adae) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi @Vatsal9195, Please try applying the library(tern)
adae <- random.cdisc.data::cadae
adae <- adae %>%
dplyr::select(USUBJID, TRT01A, AESOC, AETERM) %>%
dplyr::mutate(AETERM = factor(AETERM))
tbl <- basic_table(title = "Demo table", main_footer = "Notes") %>%
split_cols_by("TRT01A") %>%
add_colcounts() %>%
split_rows_by("AESOC", split_label = "AESOC", label_pos = "topleft") %>%
analyze_vars(vars = "AETERM", .stats = "count_fraction", .labels = "hello", na.rm = TRUE) %>%
append_topleft(" n (%)") %>%
build_table(adae)
tbl
#> Demo table
#>
#> ——————————————————————————————————————————————————————————
#> AESOC A: Drug X B: Placebo C: Combination
#> n (%) (N=609) (N=622) (N=703)
#> ——————————————————————————————————————————————————————————
#> cl A
#> trm A.1.1.1.1 64 (48.5%) 62 (47.7%) 88 (55%)
#> trm A.1.1.1.2 68 (51.5%) 68 (52.3%) 72 (45%)
#> trm B.1.1.1.1 0 0 0
#> trm B.2.1.2.1 0 0 0
#> trm B.2.2.3.1 0 0 0
#> trm C.1.1.1.3 0 0 0
#> trm C.2.1.2.1 0 0 0
#> trm D.1.1.1.1 0 0 0
#> trm D.1.1.4.2 0 0 0
#> trm D.2.1.5.3 0 0 0
#> cl B
#> trm A.1.1.1.1 0 0 0
#> trm A.1.1.1.2 0 0 0
#> trm B.1.1.1.1 56 (30.3%) 60 (30.3%) 62 (30.2%)
#> trm B.2.1.2.1 65 (35.1%) 62 (31.3%) 66 (32.2%)
#> trm B.2.2.3.1 64 (34.6%) 76 (38.4%) 77 (37.6%)
#> trm C.1.1.1.3 0 0 0
#> trm C.2.1.2.1 0 0 0
#> trm D.1.1.1.1 0 0 0
#> trm D.1.1.4.2 0 0 0
#> trm D.2.1.5.3 0 0 0
#> cl C
#> trm A.1.1.1.1 0 0 0
#> trm A.1.1.1.2 0 0 0
#> trm B.1.1.1.1 0 0 0
#> trm B.2.1.2.1 0 0 0
#> trm B.2.2.3.1 0 0 0
#> trm C.1.1.1.3 55 (53.4%) 63 (54.3%) 64 (49.6%)
#> trm C.2.1.2.1 48 (46.6%) 53 (45.7%) 65 (50.4%)
#> trm D.1.1.1.1 0 0 0
#> trm D.1.1.4.2 0 0 0
#> trm D.2.1.5.3 0 0 0
#> cl D
#> trm A.1.1.1.1 0 0 0
#> trm A.1.1.1.2 0 0 0
#> trm B.1.1.1.1 0 0 0
#> trm B.2.1.2.1 0 0 0
#> trm B.2.2.3.1 0 0 0
#> trm C.1.1.1.3 0 0 0
#> trm C.2.1.2.1 0 0 0
#> trm D.1.1.1.1 61 (32.3%) 51 (28.7%) 71 (34%)
#> trm D.1.1.4.2 66 (34.9%) 55 (30.9%) 64 (30.6%)
#> trm D.2.1.5.3 62 (32.8%) 72 (40.4%) 74 (35.4%)
#> ——————————————————————————————————————————————————————————
#>
#> Notes
tbl %>% prune_table()
#> Demo table
#>
#> ——————————————————————————————————————————————————————————
#> AESOC A: Drug X B: Placebo C: Combination
#> n (%) (N=609) (N=622) (N=703)
#> ——————————————————————————————————————————————————————————
#> cl A
#> trm A.1.1.1.1 64 (48.5%) 62 (47.7%) 88 (55%)
#> trm A.1.1.1.2 68 (51.5%) 68 (52.3%) 72 (45%)
#> cl B
#> trm B.1.1.1.1 56 (30.3%) 60 (30.3%) 62 (30.2%)
#> trm B.2.1.2.1 65 (35.1%) 62 (31.3%) 66 (32.2%)
#> trm B.2.2.3.1 64 (34.6%) 76 (38.4%) 77 (37.6%)
#> cl C
#> trm C.1.1.1.3 55 (53.4%) 63 (54.3%) 64 (49.6%)
#> trm C.2.1.2.1 48 (46.6%) 53 (45.7%) 65 (50.4%)
#> cl D
#> trm D.1.1.1.1 61 (32.3%) 51 (28.7%) 71 (34%)
#> trm D.1.1.4.2 66 (34.9%) 55 (30.9%) 64 (30.6%)
#> trm D.2.1.5.3 62 (32.8%) 72 (40.4%) 74 (35.4%)
#> ——————————————————————————————————————————————————————————
#>
#> Notes Created on 2024-08-23 with reprex v2.1.1 |
Beta Was this translation helpful? Give feedback.
Hi @Vatsal9195,
Please try applying the
prune_table()
function on your table after it is constructed instead oftrim_rows()
. You can see a reproducible example using the function with dummy data below. If this is not the result you'd like, you can find a list of other pruning functions here which can be used as input to theprune_func
argument ofprune_table()
to customize the pruning behaviour.