Skip to content

Basic stratification calculations

4 messages · dvrecko@sfu.ca, vito muggeo, Clint Harshaw +1 more

#
Hi,
if I understand correctly, tapply() is your friend here,

vito
dvrecko at sfu.ca wrote:

  
    
#
vito muggeo wrote:
Would split(y,f) be of some help here? And then you could find the mean 
for each level of f:

y.split <- split(y,f)
mean(y.split$"0")
mean(y.split$"1")
mean(y.split$"2")
mean(y.split$"3")

Clint
#
On Mar 4, 2005, at 6:55 AM, Clint Harshaw wrote:

            
You can automate this using aggregate:

 > a <- rep(c('A','B','C','D'),25)
 > b <- rnorm(100)
 > aggregate(b,by=list(a),mean)
   Group.1          x
1       A  0.1409995
2       B -0.1524387
3       C  0.3329184
4       D  0.1354157

Sean