将数据从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="\t")
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='\t')
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="\t").

该论坛的其他用户向我建议了这一点

Other users of this forum advised me this:

write.csv2(ALBERTA1, "ALBERTA1.csv")
write.table(kt, "D:/kt.txt", sep="\t", 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 -package.它不依赖的问题,并且可以读取,编辑和编写 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.