How to Create Multiple Sheets in Excel workbook Using R
In this article, we will discuss how to create multiple sheets in an excel file using the xlsx package. As we all know in general an excel file might contain one or more than one sheet present in it.
Manually we can create and insert data into multiple sheets in Excel GUI Application but when it comes to R Programming by default the data is inserted into Sheet1 but we can also modify it.
This can be achieved by specifying the sheet names in the write.xlsx() function where we want to insert data.
Syntax: write.xlsx(df, file, sheetName, col.names, row.names, append, showNA, password)
- df – data frame to be converted
- file – the path to the output excel file is specified here
- sheetName – to string is passed as sheet name
- col.names – logical value indicating if the column names of the data frame are to be written in the file
- row.names – logical value indicating if the column names of the data frame are to be written in the file
- append – when one wants to append the data to an existing file then this value needs to be marked as TRUE
- showNA- If TRUE NA(Null) Will be shown otherwise will leave as empty cells in the excel sheet
In this article, we will be requiring xlsx package to create the dataset.
Creating dataset and writing in Excel File
In this step we will add as many dataset we want and write them in the excel file. We just need to change the sheetname and it will be done.
Now we can add one more data frame in the excel file.
Similarly, we can more sheets to the file. Let’s see the output of the above code.
The output of the second sheet.
Please Login to comment...