如何在不进行大量格式化(合并,取消引号)的情况下将ftable带入R中的excel [英] How to bring ftable to excel in R without a lot of formatting (merge, unquote)

查看:125
本文介绍了如何在不进行大量格式化(合并,取消引号)的情况下将ftable带入R中的excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很想念R上的Pandas(Python)是将DataFrame导出到excel的方式. 在R中,ftable显示类似于pandas multiindex DataFrame的表.当我在pandas中使用to_excel时,每个单元格中的每一行和每一列都可以,甚至在必要时合并列名称中的单元格.

What I miss about Pandas(Python) working on R is the way a DataFrame is exported to excel. In R, ftable shows tables similar as pandas multiindex DataFrame. When I use to_excel in pandas every row and column is ok in every cell even merge cells in column names if necesary.

在R中,我尝试使用write.table进行write.ftable

In R I tried write.ftable with write.table

df = data.frame(a = c(1:6), b = rep(c('G1','G2'),3), c = rep(c('A','D','F'),2), d = c('F','F','F','F','M','M'))
df2 = ftable(xtabs(a~b+c+d, df), row.vars = 1)
write.table(write.ftable(df2))

但是我需要花很多时间在excel中设置格式(文本到列,取消引用,合并等).

But I need spend a lot of time formatting (text to column, unquoting, merging, etc) in excel.

R中有一种方法(包)可以将ftable导出为ex​​cel,而无需进行很多格式化操作. 预先感谢.

There is a way (package) in R to export ftable to excel without to make a lot of formatting things. Thanks in advance.

推荐答案

尝试一下:

library(xtable)
print(xtable(as.matrix(df2)), type = "html", file = "out.html")
file.show("out.html")

现在复制输出并将其粘贴到Excel中.

Now copy the output and paste it into Excel.

这篇关于如何在不进行大量格式化(合并,取消引号)的情况下将ftable带入R中的excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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