without a reproducible sample, it is hard to tell, but I will give it a shot. Maybe it's possible to merge your M with M2: merge(M, M2) If you only want to count times, you can use seq_along(x) in a by function eg: dat <- data.frame(person=rep(c(1,2,3), each=5), time=rnorm(15)) by(dat$person, dat$person, function(x) seq_along(x))
Ofcourse you can use any of the other vectorisation functions (lapply, apply, aggregate, ....) HTH Bart -- View this message in context: http://r.789695.n4.nabble.com/Counter-in-a-For-Loop-Efficiency-Issue-tp3253674p3253698.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.