Please first search yourself before posting. Google on "R convert list to data frame".
-- Bert On Wed, Apr 4, 2012 at 8:11 AM, Sam Steingold <s...@gnu.org> wrote: > I have a huge list (returned by fromJSON) with elements like this: > > $`zz/3260` > $`zz/3260`$name > [1] "myname" > > $`zz/3260`$status > [1] "active" > > $`zz/3260`$vectors > $`zz/3260`$vectors$`vector/241` > $`zz/3260`$vectors$`vector/241`$channel > [1] "channel/300" > > $`zz/3260`$vectors$`vector/241`$targets > $`zz/3260`$vectors$`vector/241`$targets[[1]] > $`zz/3260`$vectors$`vector/241`$targets[[1]]$range_start > [1] "0" > > $`zz/3260`$vectors$`vector/241`$targets[[1]]$range_end > [1] "99" > > I want a data frame with these column values for the above list element: > zz=3260, name="myname", status="active", vector=241, channel=300 > range_start=0, range_end=99 > > (and sometimes $vectors is an empty list, yuk!) > > my plan is to > 1 extract a list of fields > 2 convert it to a vector (which I know how to put into a data frame) > > how do I do that? > I can get "zz/3260" with names() and split it with gsub(). > I can get "myname" with as.vector(unlist(sapply(a,"[",1)))) > > is there a shortcut? > > -- > Sam Steingold (http://sds.podval.org/) on Ubuntu 11.10 (oneiric) X > 11.0.11004000 > http://www.childpsy.net/ http://truepeace.org http://mideasttruth.com > http://memri.org http://honestreporting.com http://jihadwatch.org > If you try to fail, and succeed, which have you done? > > ______________________________________________ > R-help@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. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm ______________________________________________ R-help@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.