I have codes below. It has not an error but when I weight the table with "tab_weight" it just effects inline rows. The total row numbers does not change. Total row numbers needs to change how can I do that?
And the second thing is If there is in cell it shows blank. Is it possible to change to zero "0"? For example row "Erzurum" has no case it should be shown 0 0 0 0 0 ...
df %>%
tab_cells(F1) %>%
tab_cols(tepe_kolonlari) %>%
tab_weight(sys_RespNum) %>%
tab_stat_cases(total_label = "Sum", total_row_position = "above") %>%
tab_pivot()
output is
Kadın Erkek 18 - 24 25 –34 35 - 44 45- 54 A B C1 C2 D E
#Toplam 204 122 82 25 81 98 30 76 74 15 6 3
Ankara 2832 2087 745 339 1174 1319 678 828 1145 87 94
Antalya 1203 525 678 525 678 517 686
Bursa 2257 1269 988 1038 899 320 345 902 340 670
Erzurum
Gaziantep
İstanbul 30010 18746 11264 2567 11835 15608 2462 11888 13626 1664 370
İzmir 2601 1476 1125 1416 327 858 364 198 887 333 575 244
Kayseri 199 199 199 199
Malatya 220 220 220 220
Samsun 1451 979 472 940 511 188 752 511
Tekirdağ 225 192 33 192 33 33 192
Trabzon 445 152 293 339 106 339 106
By default, total statistic is unweighted counts. You need specify weighted counts:
df %>%
tab_cells(F1) %>%
tab_cols(tepe_kolonlari) %>%
tab_weight(sys_RespNum) %>%
# 'w_cases' - weighted cases
tab_stat_cases(total_label = "Sum", total_row_position = "above", total_statistic = "w_cases") %>%
tab_pivot() %>%
# 'if_na' to show zeroes instead of blanks
if_na(0)