insurance_data
is sample data provided by the summaryrow
package.
library(knitr) # for quick tables library(summaryrow) # create reported percentage column insurance_data$reported_pct <- insurance_data$reported / insurance_data$ultimate kable(insurance_data)
table_1 <- insurance_data %>% totals_row(cols = 2:4) kable(table_1)
Additionally use the fill
argument to set the fill value supplied in summary row columns not specified in the cols
argument. The default is NA
.
table_2 <- insurance_data %>% totals_row(cols = 2:4, label_col = 1, label = "Totals:", fill = "") kable(table_2)
table_3 <- insurance_data %>% averages_row(cols = 5, label_col = 1, label = "Averages:") kable(table_3)
table_4 <- insurance_data %>% totals_row(cols = 2:4, label_col = 1, label = "Totals 2 yr:") %>% averages_row(cols = 5, label_col = 1, label = "Averages:") kable(table_4)
table_5 <- insurance_data %>% totals_row(cols = 2:4) %>% averages_row(cols = 5, label_col = 1, label = "Totals/Averages:", new_row = FALSE) kable(table_5)
table_6 <- insurance_data %>% totals_row(cols = 2:4, label_col = 1, label = "2 Yr Totals:", rows = 2:3) kable(table_6)
table_7 <- insurance_data %>% totals_row(cols = 2:4, label_col = 1, label = "2 Yr Totals:", rows = 2:3) %>% totals_row(cols = 2:4, label_col = 1, label = "Totals:") kable(table_7)
table_8 <- insurance_data %>% totals_row(cols = 2:4) %>% averages_row(cols = 5, label_col = 1, label = "Totals/Averages:", new_row = FALSE) %>% totals_row(cols = 2:4, rows = 2:3) %>% averages_row(cols = 5, label_col = 1, label = "2 Yr Totals/Averages:", rows = 2:3, new_row = FALSE) kable(table_8)
library(dplyr, warn.conflicts = FALSE) table_9 <- insurance_data %>% totals_row(cols = 2:4, label_col = 1, label = "Totals:") %>% averages_row(cols = 5, label_col = 1, label = "Totals/Averages:", new_row = FALSE) %>% dplyr::mutate(loss_cost = ultimate / exposure) kable(table_9)
table_9 <- insurance_data %>% totals_row(cols = 2:4, label_col = 1, label = "Totals:") %>% averages_row(cols = 5, label_col = 1, label = "Totals/Averages:", new_row = FALSE) # add some new columns table_9$loss_cost <- table_9$ultimate / table_9$exposure table_9$reported_pct <- table_9$reported / table_9$ultimate table_9 <- table_9 %>% format_numeric(cols = 2, digits = 0) %>% format_currency(cols = 3:4, digits = 0) %>% format_percent(cols = 5, digits = 2) %>% format_numeric(cols = 6, digits = 3) %>% format_origin(cols = 1, eval = "2017") kable(table_9)
This can be useful for adding some spacing before your summary row
table_10 <- insurance_data %>% blank_row() %>% totals_row(cols = 2:4) kable(table_10)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.