我正在寻找有关如何在 a 中显示数据表的示例或想法。在多个级别对总计进行分组的 Rmd 文档。因此,在以下示例中,日期、名称、数量、费率和价值在项目级别具有总计。
下面我只是制作了一个例子来说明我的意思:
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)),]
我需要一个像这样的实际结果,同时导出到 excel 具有特定字符值的 r 中的颜色单元格以导出到 Excel 文件,