Re: [R] Migrating from S-Plus to R - Exporting Tables

From: Gustaf Rydevik <gustaf.rydevik_at_gmail.com>
Date: Thu, 03 Jul 2008 10:00:32 +0200

On Thu, Jul 3, 2008 at 2:17 AM, jim holtman <jholtman_at_gmail.com> wrote:
> Does something like this get you close:
>
> x <- list()
> keys <- LETTERS[1:6]
> # create
> for (i in keys){
> x[[i]] <- data.frame(a=1:5, b=1:5, c=1:5)
> }
> # output
> output <- file('tempxx.txt', 'w')
> for (i in keys){
> write.table(i, row.names=FALSE, col.names=FALSE, file=output, quote=FALSE)
> write.table(x[[i]], file=output, quote=FALSE)
> }
> close(output)
>

In order to get "row.names" written above the row names, I think you have to cheat a bit:
(modifying Jim's code)

x <- list()
keys <- LETTERS[1:6]
# create
for (i in keys){

   x[[i]] <- data.frame(a=1:5, b=1:5, c=1:5) }
# output
output <- file('tempxx.txt', 'w')
for (i in keys){

   write.table(i, row.names=FALSE, col.names=FALSE, file=output, quote=FALSE)    write.table(data.frame(RowNames=row.names(x[[i]]),x[[i]]), file=output, quote=FALSE,row.names=FALSE) ##excluding actual rownames, adding them as a column.
}
close(output)



It seems as if you can't get it to write "row.names", since that is a restricted name in a dataframe, but hopefully "RowNames" is good enough.

/Gustaf

-- 
Gustaf Rydevik, M.Sci.
tel: +46(0)703 051 451
address:Essingetorget 40,112 66 Stockholm, SE
skype:gustaf_rydevik

______________________________________________
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 Thu 03 Jul 2008 - 08:13:55 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 Thu 03 Jul 2008 - 09:31:57 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