[R] Aggregating data

Doran, Harold HDoran at air.org
Wed Nov 29 20:28:27 CET 2006


David:

Is this what you are looking for?

set.seed(10)
tmp <- data.frame(group = gl(3,10), something = rnorm(30))
with(tmp, tapply(something, group, mean)) 

         1          2          3 
-0.4906568  0.3695915 -0.9129640 

> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch 
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of David Kaplan
> Sent: Wednesday, November 29, 2006 2:16 PM
> To: Chuck Cleland; r-help at stat.math.ethz.ch
> Subject: Re: [R] Aggregating data
> 
> Chuck and others.  Here is the problem I need help on.  Thanks.
> 
> --------------------
> 
> I want to follow-up on a question I had a week or so ago.  I 
> want to aggregate a very large data set.  Generally in a 
> program such as SPSS, one chooses a so-called "break 
> variable" that is the variable, and then the remaining 
> variables are aggregated by that variable with some summary 
> statistic calculated - such as the mean.
> 
> I played with "aggregate" in R and found that it requires a "by" 
> statement listing the variables.  But I don't see how I can 
> aggregate on one variable and create the summary statistics 
> on the remaining variables.  I hope that was clear.  Thanks 
> for an advice in advance.
> 
> David
> ==============================================================
> =============
> David Kaplan, Ph.D.
> Professor
> Department of Educational Psychology
> University of Wisconsin - Madison
> Educational Sciences, Room, 1061
> 1025 W. Johnson Street
> Madison, WI 53706
> 
> email: dkaplan at education.wisc.edu
> homepage: 
> http://www.education.wisc.edu/edpsych/facstaff/kaplan/kaplan.htm
> Phone: 608-262-0836
> ==============================================================
> =============
> 
> Chuck Cleland wrote:
> > David Kaplan wrote:
> >> The problem is that this doesn't seem to give what I want.  I did 
> >> look at this.  Perhaps doBy will work - haven't tried it 
> yet.  But, 
> >> any other suggestions are much appreciated.
> > 
> > David:
> >   Your posts on aggregating came to the list without any 
> text in the 
> > body of the message (I believe Petr sent a response based 
> only on the 
> > subject).  You might get more specific and helpful 
> suggestions if you 
> > send a small example of what you are trying to do and why 
> aggregate() 
> > does not work for you.  Also, be sure to send messages in 
> plain text 
> > rather than HTML.
> > 
> > hope this helps,
> > 
> > Chuck Cleland
> > 
> >> 
> =====================================================================
> >> ======
> >> David Kaplan, Ph.D.
> >> Professor
> >> Department of Educational Psychology
> >> University of Wisconsin - Madison
> >> Educational Sciences, Room, 1061
> >> 1025 W. Johnson Street
> >> Madison, WI 53706
> >>
> >> email: dkaplan at education.wisc.edu
> >> homepage: 
> >> http://www.education.wisc.edu/edpsych/facstaff/kaplan/kaplan.htm
> >> Phone: 608-262-0836
> >> 
> =====================================================================
> >> ======
> >>
> >> Petr Pikal wrote:
> >>> Similar answer as last time
> >>>
> >>> aggregate, tapply, by or ppackage doBy
> >>>
> >>> HTH
> >>>
> >>> PS. If you want to add some other text then subject in 
> your post do 
> >>> not use HTML posting as recommended in posting guide.
> >>>
> >>> Petr
> >>>
> >>>
> >>> On 28 Nov 2006 at 22:04, David Kaplan wrote:
> >>>
> >>> Date sent:      	Tue, 28 Nov 2006 22:04:09 -0600
> >>> From:           	David Kaplan <dkaplan at education.wisc.edu>
> >>> To:             	r-help at stat.math.ethz.ch
> >>> Subject:        	[R] Aggregating data
> >>>
> >>>> ______________________________________________
> >>>> R-help at stat.math.ethz.ch 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.
> >>> Petr Pikal
> >>> petr.pikal at precheza.cz
> >>>
> >> ______________________________________________
> >> R-help at stat.math.ethz.ch 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.
> >>
> >
> 
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>



More information about the R-help mailing list