Site icon R-bloggers

Export Data Frames into Multiple Excel Sheets in R

[This article was first published on Data Analysis in R » Quick Guide for Statistics & R » finnstats, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The post Export Data Frames into Multiple Excel Sheets in R appeared first on finnstats.

If you want to read the original article, click here Export Data Frames into Multiple Excel Sheets in R.

Export Data Frames into Multiple Excel Sheets in R, To export numerous data frames from R to multiple Excel worksheets, use the following basic syntax.

How to calculate Scheffe’s Test in R » finnstats

library(openxlsx)
names <- list('Sheet1' = df1, 'Sheet2' = df2, 'Sheet3' = df3)
write.xlsx(names, file = 'data.xlsx')

Export Data Frames into Multiple Excel Sheets in R

The example below demonstrates how to utilize this syntax in practice.

Exporting Multiple Data Frames to Multiple Excel Sheets is an example.

Let’s pretend we have the following three R data frames.

Plot Differences in Two Measurements-Bland-Altman Plot in R » finnstats

df1 = data.frame(Mark=c(21, 102, 13, 88),
                 ID=c('AA', 'BB', 'BB', 'CC'))
df2 = data.frame(Mark=c(100, 120, 121, 154),
                 Grade=c(7, 8,7.5, 10))
df3 = data.frame(Mark=c(11, 42, 55, 64),
                 points=c(17, 14, 22, 24))

To export all three of these data frames to distinct sheets within the same Excel file, use the following syntax.

How to measure quality control charts? (finnstats.com)

library(openxlsx)

We may now give each data frame a unique sheet name.

names <- list('Sheet1' = df1, 'Sheet2' = df2, 'Sheet3' = df3)

We may now export each data frame to its own sheet within the same Excel file.

Binomial Distribution in R-Quick Guide » finnstats

openxlsx::write.xlsx(names, file = 'data.xlsx')

Now we can view each of the data frames in their individual sheets within the same Excel file called data.xlsx use getwd() function to identify the file location the Excel sheet was exported.

Sheet1:

Sheet2:

Sheet3:

In this example, we exported three data frames to three independent Excel sheets, but the same syntax can be used to export any number of data frames.

You can make use of the read.xlsx package with append=TRUE function for executing the same.

How to Perform Dunnett’s Test in R » Post-hoc Test » finnstats

To read more visit Export Data Frames into Multiple Excel Sheets in R.

If you are interested to learn more about data science, you can find more articles here finnstats.

The post Export Data Frames into Multiple Excel Sheets in R appeared first on finnstats.

To leave a comment for the author, please follow the link and comment on their blog: Data Analysis in R » Quick Guide for Statistics & R » finnstats.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.