Skip to content
Prev 24452 / 63424 Next

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

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

set.seed(123)
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?