How to export Excel files in R language?
To export an Excel file in R language, you can use the write.xlsx function, which comes from the openxlsx package. First, you need to install and load the openxlsx package, and then use the write.xlsx function to export the data frame to an Excel file.
Here is an example code:
# 安装和加载openxlsx包
install.packages("openxlsx")
library(openxlsx)
# 创建一个示例数据框
data <- data.frame(
Name = c("Alice", "Bob", "Charlie"),
Age = c(25, 30, 35),
Score = c(85, 90, 95)
)
# 将数据框导出到Excel文件
write.xlsx(data, "output.xlsx")
In the above code, start by installing and loading the openxlsx package, then create an example data frame called data. Finally, use the write.xlsx function to export the data frame to an Excel file named output.xlsx. You can replace the name, column names, and contents of the data frame with your own data.