Steven Matthew Anderson
2009-Jun-01 07:19 UTC
[R] exporting data to csv file -problem with column names
I have a data.frame with three columns + the row number
Sample MidPoint Count
[1,] 1 0.025 1
[2,] 1 0.075 3
[3,] 1 0.125 15
[4,] 1 0.175 12
[5,] 1 0.225 5
[6,] 1 0.275 8
When I export the data to a csv the column names are shifted because
the row numbers are being exported as well.
Sample MidPoint Count
1 1 0.025 1
2 1 0.075 3
3 1 0.125 15
Is there a way to exclude the row numbers from the exported csv file?
Or add a column name for row number to keep this from happening?
I obvisouly can go into each csv file and shift the column names over
- but there are going to be a large number of csv files so I with to
automate this.
Thank you
[[alternative HTML version deleted]]
Gabor Grothendieck
2009-Jun-01 10:59 UTC
[R] exporting data to csv file -problem with column names
See exampe 6c here: http://code.google.com/p/sqldf/#Example_6._File_Input On Mon, Jun 1, 2009 at 3:19 AM, Steven Matthew Anderson <adastra69 at mac.com> wrote:> I have a data.frame with three columns + the row number > > ? ? ? ?Sample MidPoint Count > ? [1,] ? ? ?1 ? ?0.025 ? ? 1 > ? [2,] ? ? ?1 ? ?0.075 ? ? 3 > ? [3,] ? ? ?1 ? ?0.125 ? ?15 > ? [4,] ? ? ?1 ? ?0.175 ? ?12 > ? [5,] ? ? ?1 ? ?0.225 ? ? 5 > ? [6,] ? ? ?1 ? ?0.275 ? ? 8 > > When I export the data to a csv the column names are shifted because > the row numbers are being exported as well. > > > Sample ?MidPoint ? ? ? ?Count > 1 ? ? ? 1 ? ? ? 0.025 ? 1 > 2 ? ? ? 1 ? ? ? 0.075 ? 3 > 3 ? ? ? 1 ? ? ? 0.125 ? 15 > > Is there a way to exclude the row numbers from the exported csv file? > Or add a column name for row number to keep this from happening? > > I obvisouly can go into each csv file and shift the column names over > - but there are going to be a large number of csv files so I with to > automate this. > > Thank you > > > > > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > 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. >
David Winsemius
2009-Jun-01 12:01 UTC
[R] exporting data to csv file -problem with column names
On Jun 1, 2009, at 3:19 AM, Steven Matthew Anderson wrote:> I have a data.frame with three columns + the row number > > Sample MidPoint Count > [1,] 1 0.025 1 > [2,] 1 0.075 3 > [3,] 1 0.125 15 > [4,] 1 0.175 12 > [5,] 1 0.225 5 > [6,] 1 0.275 8 > > When I export the data to a csv the column names are shifted because > the row numbers are being exported as well. > > Sample MidPoint Count > 1 1 0.025 1 > 2 1 0.075 3 > 3 1 0.125 15 > > Is there a way to exclude the row numbers from the exported csv file? > Or add a column name for row number to keep this from happening??write.table Try setting row.names=FALSE in the write.table call.> I obvisouly can go into each csv file and shift the column names over > - but there are going to be a large number of csv files so I with to > automate this.> > [[alternative HTML version deleted]]And learn to send plain text to r-help. David Winsemius, MD Heritage Laboratories West Hartford, CT
Adrian Dusa
2009-Jun-01 13:58 UTC
[R] exporting data to csv file -problem with column names
Steven Matthew Anderson <adastra69 <at> mac.com> writes:> [...] > Is there a way to exclude the row numbers from the exported csv file? > Or add a column name for row number to keep this from happening?Steven, see the "row.names" argument in write.table(), set it to FALSE. Adrian