[R] Aggregating data
Chuck Cleland
ccleland at optonline.net
Wed Nov 29 21:15:17 CET 2006
Actually, I think this is a much better variation on Gabor's excellent
example:
library(nlme)
aggregate(Orthodont[c("distance","age")], by = list(Subject =
Orthodont["Subject"]), FUN =mean)
Chuck Cleland wrote:
> David Kaplan wrote:
>> 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.
>
> Another example similar to Gabor's and Harold's:
>
> library(nlme) # to get Orthodont data
>
> aggregate(Orthodont[,1:2], by = list(Subject = Orthodont$Subject), FUN =
> mean)
>
>> 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.
>>
>
--
Chuck Cleland, Ph.D.
NDRI, Inc.
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894
More information about the R-help
mailing list