I\'m new to R, and am working on a side project for my own purposes. I have this data (reproducable dput of this is at the end of the question):
X
Base version:
samp$count <- with(samp, ave(as.character(user),list(state,user),FUN=seq_along) ) out <- merge( samp[samp$state=="joined",c("user","datetime","count")], samp[samp$state=="left",c("user","datetime","count")], by=c("user","count"), all.x=TRUE ) out[order(out$count),]