An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090128/9d167acd/attachment-0001.pl>
Newbie question about "grouping"
9 messages · Rixon, John C., David Winsemius, Thomas Lumley +5 more
?by ?aggregate ?ave Further specifics might be forthcoming if self-contained example data and desired output were offered. The help pages will have worked examples, of course.
David Winsemius On Jan 28, 2009, at 9:13 AM, Rixon, John C. wrote: > Hi folks: > > I am a SQL guy who just downloaded and installed R yesterday. I am > trying to evaluate some "complex" aggregations we are currently > performing with Syncsort (and have tried in Oracle) with R. I have > loaded data in a dataframe and have performed some of the simple > aggregations on a subset of data. What I do not see how to do though, > is to "group" the aggregations on a particular key value (e.g., sum > market_value over account_id). > > If you can point me in the right direction I'd very much appreciate > it. > > Thanks! > > John > > [[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.
Some useful commands are:
by(), aggregate(), ave(), split().
eg
by(market_value, account_id, sum)
-thomas
On Wed, 28 Jan 2009, Rixon, John C. wrote:
Hi folks: I am a SQL guy who just downloaded and installed R yesterday. I am trying to evaluate some "complex" aggregations we are currently performing with Syncsort (and have tried in Oracle) with R. I have loaded data in a dataframe and have performed some of the simple aggregations on a subset of data. What I do not see how to do though, is to "group" the aggregations on a particular key value (e.g., sum market_value over account_id). If you can point me in the right direction I'd very much appreciate it. Thanks! John [[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.
Thomas Lumley Assoc. Professor, Biostatistics tlumley at u.washington.edu University of Washington, Seattle
On Wed, Jan 28, 2009 at 8:13 AM, Rixon, John C. <JCRixon at wellington.com> wrote:
Hi folks: I am a SQL guy who just downloaded and installed R yesterday. I am trying to evaluate some "complex" aggregations we are currently performing with Syncsort (and have tried in Oracle) with R. I have loaded data in a dataframe and have performed some of the simple aggregations on a subset of data. What I do not see how to do though, is to "group" the aggregations on a particular key value (e.g., sum market_value over account_id). If you can point me in the right direction I'd very much appreciate it.
Have a look at the plyr package, http://had.co.nz/plyr, and associated documentation. If you're doing pivot table type aggregations, you might also want to have a look at the reshape package, http://had.co.nz/reshape. Hadley
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090128/7b91663d/attachment-0001.pl>
?apply
x <- matrix(1:25,5) x
[,1] [,2] [,3] [,4] [,5] [1,] 1 6 11 16 21 [2,] 2 7 12 17 22 [3,] 3 8 13 18 23 [4,] 4 9 14 19 24 [5,] 5 10 15 20 25
apply(x, 2, median)
[1] 3 8 13 18 23
On Wed, Jan 28, 2009 at 11:48 AM, Frank Zhang <frankyuzhang at yahoo.com> wrote:
I am new to R. How can I get column median? Thanks.Frank
[[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.
Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?
Assuming your data are in a data.frame called dataset, apply(dataset,2,median) should work. Look at ?apply HTH, Stephan Frank Zhang schrieb:
I am new to R. How can I get column median? Thanks.Frank
[[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.
On 29/01/2009, at 8:39 AM, Stephan Kolassa wrote:
Assuming your data are in a data.frame called dataset, apply(dataset,2,median) should work. Look at ?apply
Note that apply() works with ***matrices***. The foregoing code will
work, given that all columns of ``dataset'' are numeric, due to the
fact that apply will *coerce* a data frame to a matrix.
However it should always be remembered that
DATA FRAMES ARE NOT MATRICES!!!
cheers,
Rolf Turner
######################################################################
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}
Thank you, Rolf, for this well-deserved spanking :-) I promise to amend my ways and think before I send in the future. Best, Stephan Rolf Turner schrieb:
On 29/01/2009, at 8:39 AM, Stephan Kolassa wrote:
Assuming your data are in a data.frame called dataset, apply(dataset,2,median) should work. Look at ?apply
Note that apply() works with ***matrices***. The foregoing code will
work, given that all columns of ``dataset'' are numeric, due to the
fact that apply will *coerce* a data frame to a matrix.
However it should always be remembered that
DATA FRAMES ARE NOT MATRICES!!!
cheers,
Rolf Turner
######################################################################
Attention: This e-mail message is privileged and confidential. If you
are not the intended recipient please delete the message and notify the
sender. Any views or opinions presented are solely those of the author.
This e-mail has been scanned and cleared by MailMarshal
www.marshalsoftware.com
######################################################################