From hadley at rice.edu  Fri Jan  6 20:52:22 2012
From: hadley at rice.edu (Hadley Wickham)
Date: Fri, 6 Jan 2012 13:52:22 -0600
Subject: [Rd] seq_along and rep_along
In-Reply-To: <4F074B28.8020307@gmail.com>
References: <CABdHhvEUtWfj6+2kT6fsD5CYgx66g1+C5gNhdLTA0M60Dw+YbQ@mail.gmail.com>
	<4F074B28.8020307@gmail.com>
Message-ID: <CABdHhvHPOjrKBKimuJ9F++YcXXL2y9Mn+LghAHo8k1qSc1gTDg@mail.gmail.com>

> 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/



[Rd] seq_along and rep_along
Hadley Wickham