[R] write.csv and col.names=F

Don MacQueen macq at llnl.gov
Fri Dec 18 17:09:04 CET 2009

At 9:37 PM +0800 12/18/09, 
=?UTF-8?B?UmVleWFybl/mnY7mmbrmtItfMTA5MjgxMTM=?= wrote:
>On Fri, Dec 18, 2009 at 7:52 AM, kayj <kjaja27 at yahoo.com> wrote:
>>  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)
>write.csv calls write.table to save data, is there something wrong with it?


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 

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


>Best Regards,
>Reeyarn T. Lee
>R-help at r-project.org mailing list
>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

More information about the R-help mailing list