I would like to generate a descriptive statistic by subgroup (gender of hh head) in R that is than printed into a word document.
I tried to use gtsummary but ended up not really understanding how it works. One problem that occured was that the statistics were not summarised above all surveyed households. The table rather showed each household individually.
structure(list(HHID = c("000a1b48-1223-4e6c-8d67-6a1c73f8b433",
"00147ada-cbd4-4bc9-8b65-b07ec403cf7e", "00165d72-086b-4490-9d5d-82446d9a652f",
"002552a4-59d7-4244-bc7f-f749e056d442", "00334d35-5375-4689-b39e-f000ec097d08",
"005c8a23-00f7-4a13-a7fa-b991fd597b2e"), computer = c(1, 0, 0,
0, 0, 0), bulb = c(1, 1, 1, 1, 1, 1), charger = c(1, 1, 1, 0,
1, 1), radio = c(0, 0, 0, 0, 0, 0), tv = c(1, 1, 0, 0, 1, 1),
fan = c(1, 1, 1, 1, 1, 0), fridge = c(1L, 1L, 0L, 0L, 1L,
1L), therm_app = c(1L, 0L, 1L, 0L, 1L, 0L), mech_app = c(1L,
0L, 1L, 0L, 1L, 0L), high_edu_male = c(17, 15, 12, 14, 16,
16), numhh_mem_young = c(3L, 2L, 4L, 3L, 0L, 2L), hours_grid = c(NA,
3L, 12L, 15L, 15L, 4L), gen_head = c(0, 0, 0, 0, 0, 1), high_edu_female = c(16, 9, 10, 12, 16, 12), dec_expensive = c(1, 1, 1, 1, 0, 1),
dec_clothes = c(1, 0, 1, 0, 0, 0), dec_market = c(1, 0, 1,
0, 0, 0), dec_dur = c(1, 0, 1, 0, 0, 0), dec_stove = c(1,
1, 1, 1, 0, 1), num_chairs = c(6L, 5L, 2L, 8L, 7L, 4L), num_bic = c(1L,
0L, 0L, 0L, 0L, 0L), num_motorbi = c(0L, 0L, 1L, 2L, 1L,
0L), num_car = c(2L, 0L, 0L, 0L, 1L, 0L), hh_expen = c(20000L,
5000L, 8000L, 15000L, 15000L, 15000L), own_home = c(0, 1,
0, 1, 0, 1), hhmem_room = c(1, 1.33333333333333, 1.16666666666667,
0.625, 1.5, 1)), row.names = c(NA, 6L), class = "data.frame")
This is the command I tried:
as_tibble(all_summary)
all_summary %>% tbl_summary(by = gen_head)
print(all_summary)