在R中没有列标题的情况下将数据帧写入csv文件 [英] Write a data frame to csv file without column header in R

查看:177
本文介绍了在R中没有列标题的情况下将数据帧写入csv文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将数据框的内容存储到一个.csv文件中,而不包含列名。
我使用以下代码,

I would like to store the contents of my data frame into a .csv file without the names of columns. I use the following piece of code,

write.csv(cur_data,new_file, row.names = F, col.names=F)

生成的文件如下:

"V1","V2"
-0.02868862,5.442283e-11
-0.03359281,7.669754e-12
-0.03801883,-1.497323e-10
-0.04320051,-6.557672e-11

但是我希望文件具有以下格式,

However I would like to have the file in the following format,

-0.02868862,5.442283e-11
-0.03359281,7.669754e-12
-0.03801883,-1.497323e-10
-0.04320051,-6.557672e-11

我不明白为什么不考虑代码中的col.names参数

I don't understand why the the col.names parameter in the code is not taken into consideration

推荐答案

不要使用 write.csv ,使用 write.table

 write.table( <yourdf>, sep=",",  col.names=FALSE)

您不能在 write.csv -参数只是在提醒用户。从文档中:

You cannot change many settings in write.csv -- the arguments are just there as a reminder to the user. From the documentation:


这些包装程序是故意不灵活的:它们旨在确保使用正确的约定来编写有效的文件。尝试更改附加,列名,sep,dec或qmethod的尝试将被忽略

These wrappers are deliberately inflexible: they are designed to ensure that the correct conventions are used to write a valid file. Attempts to change append, col.names, sep, dec or qmethod are ignored

这篇关于在R中没有列标题的情况下将数据帧写入csv文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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