Say I have data that looks like
date, user, items_bought, event_number 2013-01-01, x, 2, 1 2013-01-02, x, 1, 2 2013-01-03, x, 0, 3 2013-01-04, x, 0, 4 2013-0
I like James' answer better, but here's an alternative:
with(data,{ sapply(split(data,user),function(x){ sapply(x$date,function(y) sum(x$items_bought[x$date %in% c(y,y-1,y-2)])) }) })