title: Split large dataframe in R and output into separate sheets in a single Excel workbook
body: <p>Suppose I have the following dataframe in R and I am looking to split the dataframe into separate Excel sheets categorised by the Fruit column</p>
  
  <pre><code>
  +--------+-------+
  | Fruit  | Price |
  +--------+-------+
  | Apple  |    12 |
  | Apple  |    14 |
  | Apple  |    15 |
  | Orange |     2 |
  | Orange |     4 |
  | Orange |     6 |
  | Pear   |     3 |
  | Pear   |     6 |
  | Pear   |     9 |
  +--------+-------+
  
  </code></pre>
  
  <p>After splitting the dataframe into 3 separate dataframes (Apple, Orange and Pear), I intend to export each dataframe into a separate Excel sheets (named Apple, Orange and Pear) but stored within the same Excel workbook <code>Out.xlsx</code>. However, the below R code does not work. The output is an Excel workbook <code>Out.xlsx</code> with only a single sheet, Pear, containing the Pear dataframe.</p>
  
  <pre><code>library(openxlsx)
  df &lt;- read_excel("Export excel test.xlsx")
  output &lt;- split(df, df$Fruit)
  for (i in 1:length(output)){write.xlsx(x = output[i],
  file = "Out.xlsx", sheetName = names(output[i]),append = TRUE)}
  </code></pre>
  
  <p>Would anyone be able to help on this? My actual dataframe has over 4 million rows, hence I need to split the dataframe into separate sheets to circumvent Excel's row limitations</p>