More on list to data frame (was: Re: [R] List to Data Frame

Ko-Kang Kevin Wang kwan022 at stat.auckland.ac.nz
Wed Sep 18 06:24:55 CEST 2002


Hi,

I've solved the problem.  I unlisted the list into a matrix first.

For those who are interested, this is what I did:
FOO.mm <- matrix(rep(NA, length(unlist(FOO))),
                  nrow = 25, ncol = 23)
for(i in 1 : n) {
  FOO.mm[ ,i] <- unlist(FOO[[i]])
}
FRED <- as.data.frame(FOO.mm)


On Wed, 18 Sep 2002, Ko-Kang Kevin Wang wrote:

> Date: Wed, 18 Sep 2002 15:46:01 +1200 (NZST)
> From: Ko-Kang Kevin Wang <kwan022 at stat1.stat.auckland.ac.nz>
> To: R Help <r-help at stat.math.ethz.ch>
> Subject: More on list to data frame (was: Re: [R] List to Data Frame
> 
> Hi,
> 
> Now suppose I have just one list called FOO, which has 25 objects, e.g.:
>   [[1]]
>   1 2 3 4 5
>   [[2]]
>   6 7 8 9 10
>   .
>   .
>   .
> 
> And I want to do something like:
>   FRED <- data.frame(cbind(unlist(FOO[[1]]),
>                            unlist(FOO[[2]]),
>                            # ... for all 25 subsets
>                      ))
> 
> Is it possible to do this, without doing unlist(FOO[[i]]) 25 times?
> 
> Cheers,
> 
> Kevin
> 
> 
> On Fri, 23 Aug 2002, Patrick Connolly wrote:
> 
> > Date: Fri, 23 Aug 2002 17:02:37 +1200
> > From: Patrick Connolly <p.connolly at hortresearch.co.nz>
> > To: Ko-Kang Kevin Wang <kwan022 at stat.auckland.ac.nz>
> > Subject: Re: [R] List to Data Frame
> > 
> > On Fri, 23-Aug-2002 at 01:35PM +1200, Ko-Kang Kevin Wang wrote:
> > 
> > |> Hi,
> > |> 
> > |> Suppose I have two lists.  The first list is called FOO while the second
> > |> is called FRED.  
> > |> 
> > |> Say FOO looks (I've simplifed it) like:
> > |>     [[1]]
> > |>             [,1]
> > |>   [1,] 1
> > |>   [2,] 2
> > |> 
> > |>     [[2]]
> > |>             [,1]
> > |>   [1,] 3
> > |>   [2,] 4
> > |> while FRED looks like:
> > |>     [[1]]
> > |>             [,1]
> > |>   [1,] 5
> > |>   [2,] 6        
> > |> 
> > |>     [[2]]
> > |>             [,1]
> > |>   [1,] 7  
> > |>   [2,] 8
> > |> 
> > |> Can I turn this list into a dataframe which looks like:
> > |>              FOO  FRED 
> > |>   theta1.1     1     5
> > |>   theta2.1     2     6
> > |>   theta1.2     3     7
> > |>   theta2.2     4     8
> > |> or something close to this form?
> > 
> > I think this would get you pretty close:
> > 
> > data.frame(FOO = unlist(FOO), FRED = unlist(FRED))
> > 
> > 
> > best
> > 
> > 
> > -- 
> > Patrick Connolly
> > HortResearch
> > Mt Albert
> > Auckland
> > New Zealand 
> > Ph: +64-9 815 4200 x 7188
> > ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~
> > I have the world`s largest collection of seashells. I keep it on all
> > the beaches of the world ... Perhaps you`ve seen it.  ---Steven Wright 
> > ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~
> > 
> > 
> > ______________________________________________________
> > The contents of this e-mail are privileged and/or confidential to the
> > named recipient and are not to be used by any other person and/or
> > organisation. If you have received this e-mail in error, please notify 
> > the sender and delete all material pertaining to this e-mail.
> > ______________________________________________________
> > 
> 
> Cheers,
> 
> Kevin
> 
> ------------------------------------------------------------------------------
> Ko-Kang Kevin Wang
> Postgraduate PGDipSci Student
> Department of Statistics
> University of Auckland
> New Zealand
> Homepage: http://www.stat.auckland.ac.nz/~kwan022
> 
> 
> 

Cheers,

Kevin

------------------------------------------------------------------------------
Ko-Kang Kevin Wang
Postgraduate PGDipSci Student
Department of Statistics
University of Auckland
New Zealand
Homepage: http://www.stat.auckland.ac.nz/~kwan022


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list