Issue of getting empty cells in huxtable but not in expss

29 Views Asked by At

I have been producing some tables for a report and found that huxtable provided me a good option to get tables styled and auto-captioned in rmarkdown, even though I personally like expss table formats.

So, the issue is when I get expss table styled in huxtable, I started getting some cells in hux format as empty which were not exmpty in expss table. Please see below:

expss table code:

tab4 = m1 %>% 
       tab_cells(age, num_year, years) %>%
       tab_cols(sex) %>% 
       tab_stat_fun(Mean = w_mean, Median =w_median, "Std. dev." = w_sd, "Valid N" = w_n ,method = list) %>%
       tab_pivot() |>
       tab_caption("Summary statistics")
tab4

huxtable code:

as_hux(tab4) |>
   set_bottom_border(col = c(2,3,4,5,6,7,8,9), row = everywhere) |>
   set_bold(col = 1, row=everywhere) |>
   set_bold(col = c(2,3,4,5,6,7,8,9), row = c(1,2,3)) |>
   set_row_height(c(.2, .2, .2)) |>
   set_align(col = c(2,3,4,5,6,7,8,9), row = everywhere, value = "centre") 

and you can see the issue attached. The hux output should not be having Valid N (last column) empty.

What could be the problem? expss and hux outputs

I tried to see if there is any code missing from hux or how hux is treating data but I cannot find any lead.

In response to guasi's comments (the first comment), please see first 20 rows of dataframe:

structure(list(age = structure(c(32, 45, 53, 41, 68, 41, 42, 52, 52, 35, 37, 64, 54, 54, 38, 56, 33, 41, 34, 68), label = "Age (in years)", class = c("labelled", "numeric")), years = structure(c(3, 16, 20, 17, 20, 12, 11, 15, 20, 6, 1, 32, 4, 7, 12, 33, 12, 12, 10, 40), label = "Experience in field (in years)", class = c("labelled", "numeric")), num_year = structure(c(3, 20, 27, 17, 40, 12, 6, 9, 20, 8, 11, 32, 8, 20, 12, 33, 12, 4, 10, 40), label = "Experience with current office (in years)", class = c("labelled", "numeric"))), row.names = c(NA, -20L), class = c("tbl_df", "tbl", "data.frame"))

0

There are 0 best solutions below