[Rd] Behavior of seq_along (was: Create a new var reflecting the order of subjects in existing var)

Gabor Grothendieck ggrothendieck at gmail.com
Tue Apr 3 06:40:03 CEST 2007

I am moving this from r-help to r-devel.  Based on offline communications
with Jim, suppose dat is defined as follows:

dat <- data.frame(ID= c(rep(1,2),rep(2,3), rep(3,3), rep(4,4),
   rep(5,5)), var1 =rnorm(17, 35,2), var2=runif(17,0,1))

# Then this ave call works as expected:

ave(dat$ID, dat$ID, FUN = function(x) seq_along(x))

# but this apparently identical calculation gives an error:

ave(dat$ID, dat$ID, FUN = seq_along)

The only difference between the two calls is that the first one
uses seq_along and the second uses function(x) seq_along(x)
in its place.

Does anyone know why the second gives an error?  Is this
a bug in the implementation of seq_along?

More information about the R-devel mailing list