This function adds back the underlying Ns to a tabyl
whose percentages were calculated using adorn_percentages()
, to display the Ns and percentages together. You can also call it on a non-tabyl data.frame to which you wish to append Ns.
adorn_ns(dat, position = "rear", ns = attr(dat, "core"), ...)
dat | a data.frame of class |
---|---|
position | should the N go in the front, or in the rear, of the percentage? |
ns | the Ns to append. The default is the "core" attribute of the input tabyl |
... | columns to adorn. This takes a tidyselect specification. By default, all columns are adorned except for the first column and columns not of class |
a data.frame with Ns appended
mtcars %>% tabyl(am, cyl) %>% adorn_percentages("col") %>% adorn_pct_formatting() %>% adorn_ns(position = "front")#> am 4 6 8 #> 0 3 (27.3%) 4 (57.1%) 12 (85.7%) #> 1 8 (72.7%) 3 (42.9%) 2 (14.3%)