[R] Don't understand write.csv default: Why is column name for column of row names blank?

Gabor Grothendieck ggrothendieck at gmail.com
Thu Nov 1 00:35:48 CET 2007


Would this be good enough:

# example using builtin BOD data frame
write.csv(cbind(Z = row.names(BOD), BOD), row.names = FALSE)


On Oct 31, 2007 7:04 PM, Earl F. Glynn <efg at stowers-institute.org> wrote:
> I've always been frustrated that R never puts a label on the column name for
> a column of row names.  This is usually the "key" in a database table, and
> it sure would be nice to carry a "key" name along with the data instead of
> the field being blank.  So, why is it a good idea for it to be blank?
>
> ?write.csv  says this:
>
>    CSV files
>    By default there is no column name for a column of row names. If
> col.names = NA and row.names = TRUE
>    a blank column name is added, which is the convention used for CSV files
> to be read by spreadsheets.
>
>
> This last sentence doesn't make any sense to me:  "the convention used for
> CSV files to be read by spreadsheets".  Spreadsheets don't care whether this
> column is blank or has useful information.  R may have a convention to leave
> the column name for a column of row names blank (I don't understand why),
> but most other applications do not.
>
> I seem to spend a lot of time trying to get this blank field "fixed" since
> it's just not right to have a database "key" be blank.  I often must
> manually edit the .csv file written by R since that's easier than the kludge
> to put the column names in a new column one so they can have a column name
> too, and then suppress the row names in the write.csv.
>
> What am I missing?  Is there an easy way to fill this blank field  with a
> useful name for a database key when using write.csv defaults?
>
> Thanks for any insight on this.
>
> efg
>
> Earl F. Glynn
> Scientific Programmer
> Stowers Institute for Medical Research
>
> ______________________________________________
> 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.
>



More information about the R-help mailing list