Hello,
I need to export multiple tables on an excel sheet called "Sheet_data".
I can create the tables, the workbook, and the sheet using openxlsx.
However, when I combine the loop, using for, and the openxlsx package, I failed.
I know that maybe I should use assign inside the loop, but I can't figure where.
When I open the file I noticed that I export the paste order, I mean, tab_1, tab_2, and so on.
Down I provide an example of my need.
Thanks for your time and interest.
data=mpg
tab_1=data %>% filter(class=="2seater") %>% group_by(manufacturer,year) %>% count()
tab_2=data %>% filter(class=="compact") %>% group_by(manufacturer,year) %>% count()
tab_3=data %>% filter(class=="midsize") %>% group_by(manufacturer,year) %>% count()
tab_4=data %>% filter(class=="minivan") %>% group_by(manufacturer,year) %>% count()
wb_e=createWorkbook()
addWorksheet(wb_e,"Sheet_data")
for (i in 1:4) {
writeData(wb_e,"Sheet_data",paste("tab",i,sep = "_") ,startRow = 4+10*(i-1),startCol = 5)
}
saveWorkbook(wb_e,file="~/Desktop/tablex.xlsx",overwrite = TRUE)