On Fri, Aug 20, 2010 at 9:33 AM, Gabor Grothendieck <ggrothendi...@gmail.com> wrote: > On Fri, Aug 20, 2010 at 9:27 AM, Cecilia Carmo <cecilia.ca...@ua.pt> wrote: >> It wasn't the merge command. It doesn't create the variable x3. >> >> CecĂlia >> >> > > How about: > > x$k3 <- with(x, unlist(tapply(k1, k1, seq_along))) > y$k3 <- with(y, unlist(tapply(k1, k1, seq_along))) >
And here is a second one in case that one overflows as well: x$k3 <- with(x, seq_along(k1) - match(k1, k1) + 1) y$k3 <- with(y, seq_along(k1) - match(k1, k1) + 1) Note that this one assumes that the data frame is sorted by k1 which in your example it is. ______________________________________________ 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.