An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20121009/476364fb/attachment.pl>
how to convert by lists in data.frames
6 messages · Jesus Frias, Rui Barradas, ilai +1 more
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20121009/33456538/attachment.pl>
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20121009/16a27334/attachment.pl>
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
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20121009/9f6bfada/attachment.pl>
You're right, I was in a hurry. This one works. x <- rnorm(100) a <- sample(letters[1:4], 100, T) by.list <- by(x, a, summary) do.call(rbind, as.list(by.list)) (I would also prefer aggregate.) Rui Barradas Em 09-10-2012 19:46, ilai escreveu:
On Tue, Oct 9, 2012 at 12:25 PM, Bert Gunter <gunter.berton at gene.com> wrote:
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.
Agreed. In such a case I might decide to let aggregate(breaks~wool+tension, subset(warpbreaks, wool != 'A' | tension != 'H' ), summary) sort through the headache for me, and overlook the annoying "result is actually a matrix put in as a single variable in the data.frame". Personal preference maybe but that never made sense to me in the data frame construct (even if it is just a list). Cheers
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.
[[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