[R] triviality solved: Unwanted but added additional first column when using write.csv2()

Delcour Libertus delcour.libertus at gmail.com
Thu Aug 23 00:12:06 CEST 2007


Hello!

When I export a dataframe to a csv-file there is always an unwanted
column added as the following demonstrates:


> system("cat example.csv")
ID;Name;Value1;Value2
100;Tom;11,90;32,90
101;Martha;15,90;49,00
102;Ute;20,00;300,00

> write.csv2(read.csv2 ("example.csv"), "examplecopy.csv")
> system("cat examplecopy.csv")
"";"ID";"Name";"Value1";"Value2"
"1";100;"Tom";11,9;32,9
"2";101;"Martha";15,9;49
"3";102;"Ute";20;300
>

I never want the column

""
"1"
"2"
"3"

to be written into a csv-file.

I could find any hint neither in the manual nor in the archive, but then
I found the solution: row.names = FALSE

> write.csv2(read.csv2 ("example.csv"), "examplecopy.csv", row.names =
FALSE)
> system("cat examplecopy.csv")
"ID";"Name";"Value1";"Value2"
100;"Tom";11,9;32,9
101;"Martha";15,9;49
102;"Ute";20;300

But (perhaps because I am not a native in English) it was more a
solution by trial and chance than by reading and understanding the
manual. I did not expect this unwanted column to be called "row.names"
(the values are numbers which at last becomes after a subset()
completely unusuable in most cases). So I did never search for row names
but for "unwanted column write."

I did not dare to ask before because of the triviality of the question
(even I stumble over this problem for weeks) but I want the next
beginner who searches this list archive for "unwanted column" to get a
result.

Greetings

Delcour



More information about the R-help mailing list