[Rd] seq_along and rep_along

Hadley Wickham hadley at rice.edu
Fri Jan 6 20:52:22 CET 2012


> I don't see the benefit of seq_along(mtcars, 1) versus seq_len(nrow(df)) in
> readability.

I like it because:

* it reads nicely: I want a sequence along this structure in that direction
* it's more consistent: for(i in seq_along(x)) -> for(row in
seq_along(mtcars, 1))
* it generalised in a straightforward way to arrays

I don't think it's a huge improvement, but it is frustrating when base
functionality only works with vectors, not matrices, or arrays. It
would be more compelling if (e.g.) t and rev also had dimension
arguments.

Hadley

-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/



More information about the R-devel mailing list