How to bring ftable to succeed in R without a lot of formatting (merging, unquote)

What I missed about Pandas (Python) running on R is a way to export a DataFrame to excel. In R, ftable shows tables similar to the pandas multiindex DataFrame. When I use to_excel in pandas, each row and column is approved in each cell, even if it is necessary to combine the cells in the column names.

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)) 

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

In R there is a way (package) to export ftable to excel without doing a lot of formatting. Thanks in advance.

+1
r export-to-excel
source share
2 answers

Try the following:

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

Now copy the output and paste it into Excel.

+1
source share

What about:

 library(DescTools) txt <- stats:::format.ftable(df2, quote=FALSE) XLView(txt, row.names = FALSE, col.names = FALSE) 
0
source share

All Articles