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) -- Dr. rer.nat. Christoph Scherber University of Goettingen DNPW, Agroecology Waldweg 26 D-37073 Goettingen Germany phone +49 (0)551 39 8807 fax +49 (0)551 39 8806 Homepage http://www.gwdg.de/~cscherb1
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)
On 03/06/10 15:24, Christoph Scherber wrote:> 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? >save(mylist, file="/tmp/foo.RData")> But somehow I cannot get the information contained in "mylist" exported > in a nicely looking way. Any ideas? Many thanks for any help! >Define "nicely looking"? Maybe "dput" but more likely writing each data frame to its own file (or combining to one big data frame). Hope this helps a little. Allan