[R] Counter in a For Loop - Efficiency Issue

Bart Joosen bartjoosen at hotmail.com
Wed Feb 2 10:57:09 CET 2011


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.



More information about the R-help mailing list