write_xlsx() method in writexl package
The writexl package provides a method called write_xlsx() method which allows writing a data frame into an excel sheet i.e. the files of format .xls and .xlsx. The write_xlsx() method accepts a data frame and the name of the excel file in which the content of the data frame is copied into it. In order to use the write_xlsx() method, the first writexl library needs to be imported.
Syntax
library(writexl)
write_xlsx(dataframeName, “excelFile”, col_names=TRUE)
Parameters
- dataframeName – Name of the data frame that contains the data.
- excelFile – Name of the excel file into which we import from data frame.
- col_names – Write column names at the top of file if it set to True.
Syntax to install and import the writexl package:
install.package('writexl') library(writexl)
Example:
In the below code we created a data frame named “data” and imported the data in that data frame into the “write.xlsx” excel file using write_xlsx() method.
Link to the used file:- link
R
# import writexl library library (writexl) # create a data frame data <- data.frame (player= c ( 'A' , 'B' , 'C' , 'D' ), runs= c (100, 200, 408, NA ), wickets= c (17, 20, NA , 5)) # import data in dataframe to an excel sheet write_xlsx (data, "write.xlsx" ) |
Output
Reading and Writing Excel Files With R Using readxl and writexl
In this article let’s discuss reading and writing excel files using readxl and writexl packages of the R programming language.
Contact Us