Re: [R] Excluding/removing row and column names on text output files

From: Yasir Kaheil <kaheil_at_gmail.com>
Date: Fri, 02 May 2008 18:08:53 -0700 (PDT)

try:
write.table(x, file="/Users/Desktop/Data.txt", row.names= FALSE, col.names= FALSE, 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.

______________________________________________
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.
Received on Sat 03 May 2008 - 01:11:49 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 03 May 2008 - 01:30:35 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive