Append Multiple Data Frames to New Excel Sheets in R (Example Code)

In this tutorial, I’ll show how to export several data frames to new Excel worksheets in R.

Creation of Example Data

data(iris)                 # Loading iris data
data(mtcars)               # Loading mtcars data

Example: Writing Several data.frames to Multiple Excel Sheets

write.xlsx2(iris,          # Initialize xlsx file & write first data frame
            "C:/Users/Data Hacks/Desktop/my_directory/data_all.xlsx",
            row.names = FALSE,
            sheetName = "iris")
write.xlsx2(mtcars,        # Append second data frame
            "C:/Users/Data Hacks/Desktop/my_directory/data_all.xlsx",
            row.names = FALSE,
            sheetName = "mtcars",
            append = TRUE)

Further Resources & Related Articles

Have a look at the following R programming tutorials. They illustrate topics such as missing data, indices, and merging:

Leave a Reply

Your email address will not be published.

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Menu
Top