Stropharia
2008-May-03 01:02 UTC
[R] Excluding/removing row and column names on text output files
Dear R users, I've had no joy finding a solution to this online or in any of my R books. Many thanks in advance for any help you can give. I'm seeking to output a data frame (or matrix - it doesn't matter which for my purposes) to a .txt file, but omit any row or column names. The data frame that I'm using doesn't actually have column or row names to start with as it has been coerced into its present form from a matrix. When I use: capture.output(x, file="/Users/Desktop/Data.txt", append=TRUE) I get the following (this is a small fraction of the actual data frame): 1 2 3 4 5 X1 0 0 0 0 2 X2 0 0 0 2 0 X3 1 1 2 0 0 If the data frame is transformed into a matrix, I still get row and column 'names' (or at least numbers like "v1," etc.). Using the "sink" function also produces the exact same result. I've tried using "row.names=FALSE" (as you would when writing to a .csv file), in the "capture.output" function, but it doesn't work. I would also like the remove the horizontal spaces between numbers on the same row, to produce: 00002 00020 11200 But, I want each row to remain a separate entity (not be concatenated with the others). I know I can remove the blank spaces by doing Find and Replace in a text editor, but is it possible to remove the row and column names, and the row spaces, directly in R so that it outputs like the above example? Thanks, Steve ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Steven Worthington Ph.D. Candidate New York Consortium in Evolutionary Primatology & Department of Anthropology New York University 25 Waverly Place New York, NY 10003 U.S.A. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- View this message in context: http://www.nabble.com/Excluding-removing-row-and-column-names-on-text-output-files-tp17030424p17030424.html Sent from the R help mailing list archive at Nabble.com.
Yasir Kaheil
2008-May-03 01:08 UTC
[R] Excluding/removing row and column names on text output files
try: write.table(x, file="/Users/Desktop/Data.txt", row.names= FALSE, col.namesFALSE, sep="", append=TRUE) this should do it. If you don't want to append, just turn that opion off. Stropharia wrote:> > Dear R users, > > I've had no joy finding a solution to this online or in any of my R books. > Many thanks in advance for any help you can give. > > I'm seeking to output a data frame (or matrix - it doesn't matter which > for my purposes) to a .txt file, but omit any row or column names. The > data frame that I'm using doesn't actually have column or row names to > start with as it has been coerced into its present form from a matrix. > When I use: > > capture.output(x, file="/Users/Desktop/Data.txt", append=TRUE) > > I get the following (this is a small fraction of the actual data frame): > > 1 2 3 4 5 > X1 0 0 0 0 2 > X2 0 0 0 2 0 > X3 1 1 2 0 0 > > If the data frame is transformed into a matrix, I still get row and column > 'names' (or at least numbers like "v1," etc.). Using the "sink" function > also produces the exact same result. I've tried using "row.names=FALSE" > (as you would when writing to a .csv file), in the "capture.output" > function, but it doesn't work. > > I would also like the remove the horizontal spaces between numbers on the > same row, to produce: > > 00002 > 00020 > 11200 > > But, I want each row to remain a separate entity (not be concatenated with > the others). I know I can remove the blank spaces by doing Find and > Replace in a text editor, but is it possible to remove the row and column > names, and the row spaces, directly in R so that it outputs like the above > example? > > Thanks, > > Steve > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > Steven Worthington > Ph.D. Candidate > New York Consortium in > Evolutionary Primatology & > Department of Anthropology > New York University > 25 Waverly Place > New York, NY 10003 > U.S.A. > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >-- View this message in context: http://www.nabble.com/Excluding-removing-row-and-column-names-on-text-output-files-tp17030424p17030476.html Sent from the R help mailing list archive at Nabble.com.
Bob Flagg
2008-May-03 01:24 UTC
[R] Excluding/removing row and column names on text output files
?Steve, I think you can use: write.table(x, file = "?/Users/Desktop/Data.txt", sep = "", append=T, row.names = F, col.names = F) I used that for the data PERSHRUB DISTX AGE RODENTSP 1 66 2100 50 1 2 90 914 20 1 3 75 1676 34 1 4 75 243 34 1 5 60 822 16 1 6 50 121 14 1 7 5 1554 79 0 8 20 1219 58 0 9 30 2865 36 0 10 52 670 31 0 and got 662100501 90914201 751676341 75243341 60822161 50121141 51554790 201219580 302865360 52670310 Hope this helps, Bob On Fri, 2008-05-02 at 18:02 -0700, Stropharia wrote:> Dear R users, > > I've had no joy finding a solution to this online or in any of my R books. > Many thanks in advance for any help you can give. > > I'm seeking to output a data frame (or matrix - it doesn't matter which for > my purposes) to a .txt file, but omit any row or column names. The data > frame that I'm using doesn't actually have column or row names to start with > as it has been coerced into its present form from a matrix. When I use: > > capture.output(x, file="/Users/Desktop/Data.txt", append=TRUE) > > I get the following (this is a small fraction of the actual data frame): > > 1 2 3 4 5 > X1 0 0 0 0 2 > X2 0 0 0 2 0 > X3 1 1 2 0 0 > > If the data frame is transformed into a matrix, I still get row and column > 'names' (or at least numbers like "v1," etc.). Using the "sink" function > also produces the exact same result. I've tried using "row.names=FALSE" (as > you would when writing to a .csv file), in the "capture.output" function, > but it doesn't work. > > I would also like the remove the horizontal spaces between numbers on the > same row, to produce: > > 00002 > 00020 > 11200 > > But, I want each row to remain a separate entity (not be concatenated with > the others). I know I can remove the blank spaces by doing Find and Replace > in a text editor, but is it possible to remove the row and column names, and > the row spaces, directly in R so that it outputs like the above example? > > Thanks, > > Steve > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > Steven Worthington > Ph.D. Candidate > New York Consortium in > Evolutionary Primatology & > Department of Anthropology > New York University > 25 Waverly Place > New York, NY 10003 > U.S.A. > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Julian Burgos
2008-May-31 00:14 UTC
[R] Excluding/removing row and column names on text output files
Hi Steve, You can use write.table: write.table(x, file="/Users/Desktop/Data.txt", sep="",row.names=F,col.names=F) Cheers, Julian Stropharia wrote:> Dear R users, > > I've had no joy finding a solution to this online or in any of my R books. > Many thanks in advance for any help you can give. > > I'm seeking to output a data frame (or matrix - it doesn't matter which for > my purposes) to a .txt file, but omit any row or column names. The data > frame that I'm using doesn't actually have column or row names to start with > as it has been coerced into its present form from a matrix. When I use: > > capture.output(x, file="/Users/Desktop/Data.txt", append=TRUE) > > I get the following (this is a small fraction of the actual data frame): > > 1 2 3 4 5 > X1 0 0 0 0 2 > X2 0 0 0 2 0 > X3 1 1 2 0 0 > > If the data frame is transformed into a matrix, I still get row and column > 'names' (or at least numbers like "v1," etc.). Using the "sink" function > also produces the exact same result. I've tried using "row.names=FALSE" (as > you would when writing to a .csv file), in the "capture.output" function, > but it doesn't work. > > I would also like the remove the horizontal spaces between numbers on the > same row, to produce: > > 00002 > 00020 > 11200 > > But, I want each row to remain a separate entity (not be concatenated with > the others). I know I can remove the blank spaces by doing Find and Replace > in a text editor, but is it possible to remove the row and column names, and > the row spaces, directly in R so that it outputs like the above example? > > Thanks, > > Steve > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > Steven Worthington > Ph.D. Candidate > New York Consortium in > Evolutionary Primatology & > Department of Anthropology > New York University > 25 Waverly Place > New York, NY 10003 > U.S.A. > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >-- Julian M. Burgos Fisheries Acoustics Research Lab School of Aquatic and Fishery Science University of Washington 1122 NE Boat Street Seattle, WA 98105 Phone: 206-221-6864