[R] Exporting a list of data frames

Christoph Scherber Christoph.Scherber at agr.uni-goettingen.de
Thu Jun 3 17:20:25 CEST 2010


Dear all,

I found one possible solution using a single call to write.table:

# assuming that mylist is a named list of data.frames:
data(Orange)
mylist=list(Orange1=Orange,Orange2=Orange,Orange3=Orange)

sapply(1:length(mylist),
      function(x){
		write.table(
			data.frame(mydf=rep(names(mylist)[[x]],dim(mylist[[x]])[1]),mylist[[x]]),
			sep="\t",append=T,file="My.data.frames.txt")
}
)


Best wishes,
Christoph




> Dear R helpers,
>
> Suppose I have a list of data frames. How can I export them
> (e.g. as a
> text file) without losing the columns of the individual
> data.frames?
>
> Example:
>
> data(Orange)
> mylist=list(Orange1=Orange,Orange2=Orange,Orange3=Orange)
>
>
> I would like to use something like
>
> write(mylist,"mylist.txt")
>
> or
>
> format (mylist...)
>
> But somehow I cannot get the information contained in
> "mylist" exported
> in a nicely looking way. Any ideas? Many thanks for any
> help!
>
> Best wishes,
> Christoph
>
>
> (using R 2.11.0 on Windows XP)



More information about the R-help mailing list