Thank you Jorge, this is exactly what I needed!
Another solution that works too, suggested by Steve:group.med <- tapply( rt, 
list(group, session), median)
From: jorgeivanve...@gmail.com
Date: Wed, 8 Dec 2010 09:43:47 -0500
Subject: Re: [R] How can I calculate the median for each factor combination?
To: mariannestep...@hotmail.com
CC: r-help@r-project.org

Hi Marianne,
Please consider the following:


with(table, aggregate(rt, list(group, session), FUN = median))


HTH,Jorge


On Wed, Dec 8, 2010 at 9:29 AM, Marianne Stephan <> wrote:




Hello everybody,

I would like to calculate the median for each factor combination, with only one 
value per factor combination as an output.

Could anybody help me?





For example:

# make table

g<-1:2

group<-rep(g, each=5)

session<-c(1,1,2,2,2,1,1,1,2,2)

rt<-seq(length=10,300, 800)

rt<-round(rt, digits=2)

table<-data.frame(group, session, rt)

table



 á group session á á rt

1 á á á1 á á á 1 300.00

2 á á á1 á á á 1 355.56

3 á á á1 á á á 2 411.11

4 á á á1 á á á 2 466.67

5 á á á1 á á á 2 522.22

6 á á á2 á á á 1 577.78

7 á á á2 á á á 1 633.33

8 á á á2 á á á 1 688.89

9 á á á2 á á á 2 744.44

10 á á 2 á á á 2 800.00









Besides others I tried the following:

median<-ave(rt, group, session, FUN=median)

median<-frameApply(table,by=c("group", "session"), on="rt", fun=median)



I would appreciate your help a lot.

Marianne

 á á á á[[alternative HTML version deleted]]



______________________________________________

R-help@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@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.

Reply via email to