[英]R: Export Multiple Excel Workbooks from dataframe
I have a dataframe of deals by person.我有一个 dataframe 的个人交易。 I have multiple people (30+) and I want to send them a report of just their deals.
我有多个人(30 岁以上),我想向他们发送一份关于他们的交易的报告。 Rather than manually creating 30+ individual excel workbooks, is there a package in R that can do this?
而不是手动创建 30 多个单独的 excel 工作簿,R 中是否有 package 可以做到这一点?
Below is my dummy data下面是我的虚拟数据
df <- tibble(
Deal = c("Deal A", "Deal B", "Deal C", "Deal D", "Deal E", "Deal F", "Deal G", "Deal H"),
Person = c("john", "henry", "max", "felix", "henry", "john", "max", "max")
)
The expected result of the dummy data is to have 4 (by person) separate excel workbooks with deal data so I can send it to the people via email.虚拟数据的预期结果是有 4 个(按人)单独的 excel 工作簿和交易数据,所以我可以通过 email 将其发送给人们。
Bonus points if I can format workbooks to all have bold header and format table with $ for numbers and dates for dates!如果我可以将工作簿格式化为所有具有粗体 header 的工作簿并使用 $ 为数字和日期的日期格式化表格,则可以获得奖励积分!
To expand on my comment above:要扩展我上面的评论:
library(tidyverse)
# Other packages for handling xlsx files are available
library(xlsx)
df %>%
group_by(Person) %>%
group_walk(
function(.x, .y) {
write.xlsx(.x, paste0(.y$Person, ".xlsx"), sheet="Sheet1")
}
)
After running this code, I see the following files in my current working directory运行此代码后,我在当前工作目录中看到以下文件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.