将数据从 R 导出到 Excel [英] Export data from R to Excel

查看:61
本文介绍了将数据从 R 导出到 Excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写代码将数据库从 R 导出到 Excel,我一直在尝试其他代码,包括:

I am writing codes to export database from R into Excel, I have been trying others codes including:

write.table(ALBERTA1, "D:/ALBERTA1.txt", sep="	")
write.csv(ALBERTA1,":ALBERTA1.csv")
your_filename_in_R = read.csv("ALBERTA1.csv")
your_filename_in_R = read.csv("ALBERTA1.csv")
write.csv(df, file = "ALBERTA1.csv")
your_filename_in_R = read.csv("ALBERTA1.csv")
write.csv(ALBERTA1, "ALBERTA1.csv")
write.table(ALBERTA1, 'clipboard', sep='	')
write.table(ALBERTA1,"ALBERTA1.txt")
write.table(as.matrix(ALBERTA2),"ALBERTA2.txt")
write.table(as.matrix(vecm.pred$fcst$Alberta_Females[,1]), "vecm.pred$fcst$Alberta_Females[,1].txt")
write.table(as.matrix(foo),"foo.txt")
write.xlsx(ALBERTA2, "/ALBERTA2.xlsx")
write.table(ALBERTA1, "D:/ALBERTA1.txt", sep="	").

此论坛的其他用户建议我这样做:

Other users of this forum advised me this:

write.csv2(ALBERTA1, "ALBERTA1.csv")
write.table(kt, "D:/kt.txt", sep="	", row.names=FALSE)

你可以在图片上看到我从上面的代码中得到的结果.但是这个数字不能用于进行任何进一步的操作,例如与其他矩阵的加法.

You can see on the pictures the outcome I have got from this codes above. But this numbers can't be used to make any further operations such as addition with other matrices.

有人遇到过这种问题吗?

Has someone experienced this kind of problems?

推荐答案

另一个选项是 openxlsx 包.它不依赖于 并且可以阅读,编辑和编写 Excel 文件.来自包装的描述:

Another option is the openxlsx-package. It doesn't depend on java and can read, edit and write Excel-files. From the description from the package:

openxlsx 简化了从 R 编写和设置 Excel xlsx 文件的过程,并消除了对 Java 的依赖

openxlsx simplifies the the process of writing and styling Excel xlsx files from R and removes the dependency on Java

示例用法:

library(openxlsx)

# read data from an Excel file or Workbook object into a data.frame
df <- read.xlsx('name-of-your-excel-file.xlsx')

# for writing a data.frame or list of data.frames to an xlsx file
write.xlsx(df, 'name-of-your-excel-file.xlsx')

除了这两个基本功能之外,openxlsx-包还有许多其他用于操作 Excel-文件的功能.

Besides these two basic functions, the openxlsx-package has a host of other functions for manipulating Excel-files.

例如,使用 writeDataTable 函数,您可以在 Excel 文件中创建格式化表格.

For example, with the writeDataTable-function you can create formatted tables in an Excel-file.

这篇关于将数据从 R 导出到 Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆