I have a data frame that I run a few analyses on and I want to export the results to Excel files. One workbook per group and each analysis results on a separate tab. I would prefer to use openxlsx for the exporting to take java out of the equation.
library(plyr)
library(dplyr)
library(openxlsx)
df <- iris
# Analysis 1
results1 <- df %>%
group_by(Species) %>%
summarise(count = n())
# Analysis 2
results2 <- df %>%
group_by(Species) %>%
summarise(mean.sl = mean(Sepal.Length),
mean.sw = mean(Sepal.Width))
My desired export output would be three Excel workbooks, setosa.xlsx, versicolor.xlsx, and virginica.xlsx; each with two sheets "results1" and "results2" containing only their within-group results. Meaning no setosa rows in the versicolor Excel file.
I tried to split results1 and results2 into lists of data frames in order to use lappy with write.xlsx but I'm not able to make it work.
r1_list <- dlply(results1, .(Species))
r2_list <- dlply(results2, .(Species))
Other suggestions?
xlsxpackage is what you're looking forxlsxdepends on java, which I'm trying to avoid, if possible