combine_table.Rd
This function combines two tables: one with raw counts and another with percentages (or other calculated values). It returns a formatted table that merges these values in a "count (percentage)" format.
combine_table(tab1, tab2, percent = TRUE)
A data frame with the combined counts and percentages (or values).
This function takes two tables, converts them to data frames, and then combines their values in a "count (percentage)" format. If the percent
argument is TRUE
, the values in tab2
are treated as percentages; otherwise, they are combined as raw values.
tab1<-margin.table(Titanic,c(1,4))
tab2 <- round(prop.table(tab1, margin = 1) * 100, 2)
combine_table(tab1,tab2,)
#> No Yes
#> 1st 122 (37.54%) 203 (62.46%)
#> 2nd 167 (58.6%) 118 (41.4%)
#> 3rd 528 (74.79%) 178 (25.21%)
#> Crew 673 (76.05%) 212 (23.95%)