Skip to content

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.
#
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:

            
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:
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
#
?apply
[,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
[1]  3  8 13 18 23

        
On Wed, Jan 28, 2009 at 11:48 AM, Frank Zhang <frankyuzhang at yahoo.com> wrote:

  
    
#
Assuming your data are in a data.frame called dataset,

apply(dataset,2,median)

should work. Look at

?apply

HTH,
Stephan


Frank Zhang schrieb:
#
On 29/01/2009, at 8:39 AM, Stephan Kolassa wrote:

            
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: