If I am reading your question correctly, something like the following should do it: `aggregate(x$Objects,by=list(x$SessionNo.),sum)` where `x` is the data frame containing your data. This will give you, for each unique session number, the sum of the object counts. You can of course substitute other functions (including your own) on place of the `sum`.