Discussion:
[R] write.csv and col.names=F
kayj
2009-12-17 23:52:45 UTC
Permalink
Hi All,

I always have a problem with write.csv when I want the column names to be
ignored, when I specify col.names=F, I get a header of V1 V2 V3 V4 etc.

for example I tried

write.csv(mydata, file="data.csv", quote=FALSE, row.names=F, col.names=F)
Warning message:
In write.csv(mydata, file = "data.csv", quote = FALSE, :
attempt to set 'col.names' ignored
how can I get rid of this problem ? I do not want the header of V1 V2 V3...
to appear in my output file,

Thanks
--
View this message in context: http://n4.nabble.com/write-csv-and-col-names-F-tp974477p974477.html
Sent from the R help mailing list archive at Nabble.com.
milton ruser
2009-12-18 07:34:38 UTC
Permalink
An embedded and charset-unspecified text was scrubbed...
Name: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20091218/8985e336/attachment-0001.pl>
Gabor Grothendieck
2009-12-18 12:30:03 UTC
Permalink
Use write.table instead.
Post by kayj
Hi All,
I always have a problem with write.csv when I want the column names to be
ignored, when I specify col.names=F, I get a header of V1 V2 V3 V4 etc.
for example I tried
write.csv(mydata, file="data.csv", quote=FALSE, row.names=F, col.names=F)
?attempt to set 'col.names' ignored
how can I get rid of this problem ? I do not want the header of V1 V2 V3...
to appear in my output file,
Thanks
--
View this message in context: http://n4.nabble.com/write-csv-and-col-names-F-tp974477p974477.html
Sent from the R help mailing list archive at Nabble.com.
______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reeyarn_李智洋_10928113
2009-12-18 13:37:41 UTC
Permalink
Post by kayj
Hi All,
I always have a problem with write.csv when I want the column names to be
ignored, when I specify col.names=F, I get a header of V1 V2 V3 V4 etc.
I tried that and found the same problem, however, I found
write.table(mydata, file="data.csv",col.names=F)
works.

write.csv calls write.table to save data, is there something wrong with it?

--
Best Regards,
Reeyarn T. Lee
jim holtman
2009-12-18 14:04:08 UTC
Permalink
An embedded and charset-unspecified text was scrubbed...
Name: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20091218/bc0cd9ca/attachment-0001.pl>
Don MacQueen
2009-12-18 16:09:04 UTC
Permalink
At 9:37 PM +0800 12/18/09,
Post by Reeyarn_李智洋_10928113
Post by kayj
Hi All,
I always have a problem with write.csv when I want the column names to be
ignored, when I specify col.names=F, I get a header of V1 V2 V3 V4 etc.
I tried that and found the same problem, however, I found
write.table(mydata, file="data.csv",col.names=F)
works.
write.csv calls write.table to save data, is there something wrong with it?
No.

If you read the help page you will find that it answers your question. It says:

'write.csv' and 'write.csv2' provide convenience wrappers for
writing CSV files. They set 'sep', 'dec' and 'qmethod', and
'col.names' to 'NA' if 'row.names = TRUE' and 'TRUE' otherwise.

Notice that it sets col.names for you.
If you want full control, use write.table().
If you want to write a table in a commonly used and pre-defined
format (and without having to worry about various options) use
write.csv().

That's why it is a called "convenience wrapper".

-Don
Post by Reeyarn_李智洋_10928113
--
Best Regards,
Reeyarn T. Lee
______________________________________________
R-help at r-project.org mailing list
https://*stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://*www.*R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
--
--------------------------------------
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA
925-423-1062
Loading...