VOOZH about

URL: https://www.geeksforgeeks.org/r-language/write-data-into-excel-using-r/

⇱ Write Data Into Excel Using R - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Write Data Into Excel Using R

Last Updated : 23 Jul, 2025

In this article, we will discuss how to write data into excel using R Programming Language

To write data into excel,  we must leverage a package called xlsx in R. The excel package is a java based language that is powerful to read, write and update data from and to excel files.

Syntax: write.xlsx(data, file, sheetName, col.names, row.names, append)

Parameters:

  • data - the dataframe to be written to excel file
  • file - the output path in which the excel file has to be stored
  • sheetName - desired name for the sheet
  • row.names, col.names - (bool) if true the row and column names are copied to the excel file
  • append - if True data will be appended to the existing excel file

Let us use the inbuilt iris dataset and store the existing dataset in the excel file with the name iris.xlsx and sheet name iris_data.

Output:

👁 Image
Output

Now let us use the same file and use the append parameter to append another dataset in a separate sheet. For this purpose, let us use another inbuilt dataset called mtcars and append it to the existing file as shown in the below code.

Output:

👁 Image
Output
Comment
Article Tags:
Article Tags:

Explore