[R] how to convert by lists in data.frames

Bert Gunter gunter.berton at gene.com
Tue Oct 9 20:25:47 CEST 2012


Ilai, et. al:

Yes. The OP might also look at the result of:

> t(simplify2array (by.list))

The only wrinkle here (with either rbind or simplify2array) is getting
the labels correct if the design is not fully crossed -- i.e. if some
groups are missing so that expand.grid() won't work. Then you might
have to work harder to extract the information from by.list.

> str(by.list)

might help here.

-- Bert

On Tue, Oct 9, 2012 at 11:14 AM, ilai <keren at math.montana.edu> wrote:
> On Tue, Oct 9, 2012 at 11:42 AM, Rui Barradas <ruipbarradas at sapo.pt> wrote:
>
>> Hello,
>>
>> Try
>>
>> do.call(data.frame, by.list)
>>
>>
> I don't think data.frame inside do.call works in this context. May need it
> on the outside to do the job (Only OK here since there is no mixture of
> numeric and character/factors in this summary). Something like
>
> by.list <- by(warpbreaks[, 1], warpbreaks[, -1], summary)
> by.dtfrm <- data.frame( do.call( rbind, by.list ) )
> by.dtfrm <- cbind( do.call( expand.grid, attr( by.list, 'dimnames' ) ),
> by.dtfrm )
>
>
>
>
> Hope this helps,
>>
>> Rui Barradas
>> Em 09-10-2012 17:53, Jesus Frias escreveu:
>> > Dear R-helpers,
>> >
>> >
>> >
>> > I've got a summary of results from a by() call that I am making with a
>> list
>> > of more than two of factors not very different from the example in the
>> by()
>> > help page
>> >
>> >
>> >
>> > require(stats)
>> >
>> > by(warpbreaks[, 1],   warpbreaks[, -1],       summary)
>> >
>> >
>> >
>> > The result of the command gives a list of the form
>> >
>> >
>> >
>> > wool: A
>> > tension: L
>> >     Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
>> >    25.00   26.00   51.00   44.56   54.00   70.00
>> > ---------------------------------------------------
>> > wool: B
>> > tension: L
>> >     Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
>> >    14.00   20.00   29.00   28.22   31.00   44.00
>> > ---------------------------------------------------
>> >
>> > .... And so on.
>> >
>> >
>> >
>> >
>> >
>> > I would like to convert this result in to a flat data.frame with variable
>> > names:
>> >
>> >
>> >
>> > Wool, Tension, Min, 1stQ, Median, Mean, 3rdQ, Max
>> >
>> > A, L , 25.00   26.00   51.00   44.56   54.00   70.00
>> > B,  L, 14.00   20.00   29.00   28.22   31.00   44.00
>> >
>> > ....
>> >
>> >
>> >
>> >
>> >
>> > Although I've tried the argument "simplify=T" I haven't been able to get
>> > this converted.
>> >
>> >
>> >
>> > Is there a simple way to achieve this?
>> >
>> >
>> >
>> > Thanks in advance!
>> >
>> >
>> >
>> > Regards,
>> >
>> >
>> >
>> > Jesus
>> >
>> >
>> >
>> > Jesús María Frías Celayeta, PhD
>> >
>> > Ceann Cúntóir, Scoil Eolaíocht an Bhia agus Sláinte an Chomhshaoil
>> >
>> > Assistant Head, School of Food Science and Environmental Health,
>> >
>> > Coláiste Eolaíochtaí agus Sláinte/ College of Sciences and Health,
>> >
>> > Institiúid Teicneolaíochta Átha Cliath/ Dublin Institute of Technology,
>> >
>> > Sráid Chathal Brugha, Baile Átha Cliath 1, Éire/Cathal Brugha Street,
>> Dublin
>> > 1, Ireland
>> >
>> > F: +353-1-4024459
>> >
>> > E:  <mailto:james.curtin at dit.ie> jesus.frias at dit.ie
>> >
>> > W: http://fseh.dit.ie/o4/StaffListing/JesusFrias.html
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> > Tá an teachtaireacht seo scanta ó thaobh ábhar agus víreas ag Seirbhís
>> Scanta Ríomhphost de chuid Seirbhísí Faisnéise, ITBÁC agus meastar í a
>> bheith slán.  http://www.dit.ie
>> >
>> > This message has been scanned for content and viruses by the DIT
>> Information Services E-Mail Scanning Service, and is believed to be clean.
>> http://www.dit.ie
>> >
>> >
>> >       [[alternative HTML version deleted]]
>> >
>> >
>> >
>> > ______________________________________________
>> > 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.
>>
>>
>>         [[alternative HTML version deleted]]
>>
>>
>> ______________________________________________
>> 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.
>>
>>
>
>         [[alternative HTML version deleted]]
>
>
> ______________________________________________
> 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.
>



-- 

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




More information about the R-help mailing list