I'm looking for examples or ideas on how I might display a data table in a. Rmd document that has grouped totals at multiple levels. So, in the example following, the date, names, qty, rate, and value have a total at the items level.
Following I just crafted an example to illustrate what I mean:
names <- c('note','pen','book','note','pen','book')
qty <- c(150, 100, 200, 50, 150, 75)
date <- c('1-mar-2019','1-mar-2019','1-mar-2019', '2-mar-2019','2-mar-2019','2-mar-2019')
rate <- c(10, 5, 20, 10, 5, 20)
stationary <- data.frame(date, names, qty, rate)
stationary$value = stationary$qty*stationary$rate
library(tidyverse)
stationary <- stationary %>%
group_by(names) %>%
summarise(qty = sum(qty), value = sum(value)) %>%
ungroup() %>%
mutate(names = paste0(names, " total")) %>%
bind_rows(stationary)
stationary %>%filter(grepl("total", names)) %>%summarise(qty = sum(qty),value = sum(value)) %>% mutate(names = "Total (Grand)") %>% bind_rows(stationary) %>% arrange(names)
stationary = stationary[, c(4,1,2,5,3)]
stationary = stationary[with(stationary, order(stationary$names)),]
I need an actual result like this snap while export to excel Color cells with specific character values in r to export to Excel file,