Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To populate an Excel file from R, you can use the openxlsx package. Here are the general steps:

  1. Install and load the openxlsx package:
install.packages("openxlsx")
library(openxlsx)
  1. Create a new Excel workbook and specify a sheet:
wb <- createWorkbook()
sheet <- addWorksheet(wb, "Sheet 1")
  1. Write data to the sheet using functions like writeData() or writeDataTable():
writeData(sheet, mtcars)
  1. Save the workbook:
saveWorkbook(wb, "myWorkbook.xlsx")

This will create an Excel file named "myWorkbook.xlsx" in your working directory with the data from the mtcars dataset in the first sheet. You can customize the sheet name, data range, and other options as needed.