Go to TogaWare.com Home Page. Data Science Desktop Survival Guide
by Graham Williams
Duck Duck Go



CLICK HERE TO VISIT THE UPDATED SURVIVAL GUIDE

Write Excel Data

20200601 An Excel spreadsheet can be written using xlsx. The basic functionality of xlsx::write.xlsx() is to write a data frame to the spreadsheet. Using rattle::weatherAUS a more sophisticated example will create a new workbook using xlsx::createWorkbook(). For each location a new sheet is created using xlsx::createSheet() which is then populated using xlsx::addDataFrame(). Once all locations are added as separate sheets to the workbook we can write the actual spreadsheet using xlsx::saveWorkbook().

options(java.parameters="-Xmx8000m")
library(xlsx)         # Write Excel spreadsheets: write.xlsx() saveWorkbook().

locations <- unique(ds$Location)
wb <- createWorkbook(type="xlsx")

for (l in locations)
{
  wb %>%
    createSheet(sheetName=l) ->
  ws

  ds %>%
    filter(Location==l) %>%
    select(-Location) %>%
    data.frame() %>%
    addDataFrame(sheet=ws, row.names=FALSE)
}

saveWorkbook(wb, 'weatherAUS.xlsx')

Notice the use of the java.parameters= option to specify a larger allocation of memory for Java. This is required for even moderate sized datasets like the rattle::weatherAUS dataset. The option needs to be specified before the package is loaded.

See Section 6.4 for an example of using this created spreadsheet.


Support further development by purchasing the PDF version of the book.
Other online resources include the GNU/Linux Desktop Survival Guide.
Books available on Amazon include Data Mining with Rattle and Essentials of Data Science.
Popular open source software includes rattle and wajig.
Hosted by Togaware, a pioneer of free and open source software since 1984.
Copyright © 2000-2020 Togaware Pty Ltd. . Creative Commons ShareAlike V4.