forked from waddella/rtables_rinpharma2022
-
Notifications
You must be signed in to change notification settings - Fork 0
/
14_exercise.R
89 lines (65 loc) · 2.32 KB
/
14_exercise.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
library(rtables)
library(dplyr)
# Default split function NULL ----
# splits by factor levels
lyt <- basic_table() |>
split_cols_by("ARM") |>
analyze("AGE", mean, format = "xx.xx")
build_table(lyt, ex_adsl)
# Documentation ----
# of existing split functions
?drop_split_levels
# Reorder Levels ----
# (instead of changing the factor levels with fct_relevel)
lyt <- basic_table() |>
split_cols_by(
var = "ARM",
split_fun = reorder_split_levels(c("B: Placebo", "A: Drug X", "C: Combination"))
) |>
analyze("AGE", mean, format = "xx.xx")
build_table(lyt, ex_adsl)
# Add overall column ----
lyt <- basic_table() |>
split_cols_by("ARM", split_fun = add_overall_level()) |>
analyze("AGE", mean, format = "xx.xx")
build_table(lyt, ex_adsl)
## move Overall to last column
lyt <- basic_table() |>
split_cols_by("ARM", split_fun = add_overall_level(first = FALSE)) |>
analyze("AGE", mean, format = "xx.xx")
build_table(lyt, ex_adsl)
## overall in nested
## move Overall to last column
ex_adsl2 <- ex_adsl |>
filter(SEX %in% c("M", "F")) |>
mutate(SEX = droplevels(SEX))
lyt <- basic_table() |>
split_cols_by("ARM", split_fun = add_overall_level(first = FALSE)) |>
split_cols_by("SEX") |>
analyze("AGE", mean, format = "xx.xx")
build_table(lyt, ex_adsl2)
## or overall for each ARM
lyt <- basic_table() |>
split_cols_by("ARM") |>
split_cols_by("SEX", split_fun = add_overall_level(first = FALSE)) |>
analyze("AGE", mean, format = "xx.xx")
build_table(lyt, ex_adsl2)
## or both
lyt <- basic_table() |>
split_cols_by("ARM", split_fun = add_overall_level(first = FALSE)) |>
split_cols_by("SEX", split_fun = add_overall_level(first = FALSE)) |>
analyze("AGE", mean, format = "xx.xx")
build_table(lyt, ex_adsl2)
## or only one overall column not nested
## TODO
lyt <- basic_table() |>
split_cols_by("ARM") |>
split_cols_by("SEX") |>
analyze("AGE", mean, format = "xx.xx")
build_table(lyt, ex_adsl2)
# A: Drug X B: Placebo C: Combination Overall
# F M F M F M
# ————————————————————————————————————————————————————————------------
# mean 32.76 35.57 34.12 37.44 35.20 35.38 34.88
# Other split functions ----
# TODO