That seems to work. I should add that to make "ave" work like "by" one can
do:

mydata$newvar <- ave(1:nrow(mydata), mydata$some_factor, FUN= function (x) {
  x <- ds[x,]
# ... etc...
})

Thanks!
David

	[[alternative HTML version deleted]]


