Re: [R] Differences per group

2011-03-09 Thread Dennis Murphy
Hi: Here's another approach: purchase_amount <- transform(purchase_amount, diff = with(purchase_amount, ave(amount, customer, FUN = function(x) c(0, diff(x) purchase_amount HTH, Dennis On Wed, Mar 9, 2011 at 7:27 AM, rens_1112 wrote: > Dear all, > > Probably a rather stupid quest

Re: [R] Differences per group

2011-03-09 Thread Jorge Ivan Velez
Hi Rens, One way would be x$difference <- do.call(c, with(x, tapply(amount, customer, function(x) c(0, diff(x) x Take a look at ?tapply and ?aggregate for more information. HTH, Jorge On Wed, Mar 9, 2011 at 10:27 AM, rens_1112 <> wrote: > Dear all, > > Probably a rather stupid question,