Message-ID: <20090302102803.h0ujticujo8sck00@webmail.uni-bremen.de>
Date: 2009-03-02T09:28:03Z
From: Patrick Hausmann
Subject: ave and grouping
Dear list,
# I have a DF like this:
sleep$b <- c(rep(8,10), rep(9,10))
sleep$me <- with(sleep, ave(extra, group, FUN = mean))
sleep
# I would like to create a new variable
# holding the b-th value of group 1 and 2.
# This is not what I want, it takes always the '8' from group '1'
# and not the '9'
sleep$gr <- with(sleep, ave(extra, group, FUN = function(x) x[ b[1] ]))
sleep
Thanks for any help!
Patrick