如何避免在使用xlsx包保存data.frame时编写row.names列 [英] How to avoid writing a row.names column when saving a data.frame using the xlsx package

查看:115
本文介绍了如何避免在使用xlsx包保存data.frame时编写row.names列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像下面这样的数据框,我真的想删除行名,当我使用xlsx包导出到一个excel文件。

  bd<  -  data.frame(id = 1:200,A = c(rep(One,100),rep(Two,100)),
B = c(rep(1,50),rep(0,50),rep(1,50),rep(0,50)))

我已经尝试使用下面的命令,但是它们保留在excel文件的第一列。

  bd<  -  data.frame(id = 1:200,A = c(rep(One,100),rep(Two,100)),
B = c(rep(1,50),rep(0,50),rep(1,50),rep(0,50)),row.names = NULL)
/ pre>

有没有办法这样做?

解决方案

将rownename设置为 NULL 以删除它们:

  rownames(bd) <  -  NULL 

另外,从xlsx文档:

  write.xlsx(x,file,sheetName =Sheet1,
col.names = TRUE,row.names = TRUE,append = FALSE)

将row.names设置为 FALSE 以避免第一列为行名。


I have a data frame like this one below and I really want to remove the row names when I export it to a excel file using the xlsx package.

bd <- data.frame(id = 1:200, A = c(rep("One", 100), rep("Two", 100)), 
             B = c(rep(1,50), rep(0, 50), rep(1, 50), rep(0, 50)))

I have already tried to use the command below, but it keep them in the first column of the excel file.

bd <- data.frame(id = 1:200, A = c(rep("One", 100), rep("Two", 100)), 
             B = c(rep(1,50), rep(0, 50), rep(1, 50), rep(0, 50)), row.names=NULL)

Is there any way to do this?

解决方案

Set the rownames to NULL to remove them:

rownames(bd) <- NULL

Also, from xlsx documentation:

write.xlsx(x, file, sheetName="Sheet1",
           col.names=TRUE, row.names=TRUE, append=FALSE)

Set row.names to FALSE to avoid the first column being row names.

这篇关于如何避免在使用xlsx包保存data.frame时编写row.names列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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