Re: [Rd] seq_along and rep_along

From: Duncan Murdoch <murdoch.duncan_at_gmail.com>
Date: Fri, 06 Jan 2012 14:27:36 -0500

On 12-01-06 1:31 PM, Hadley Wickham wrote:
> Hi all,
>
> A couple of ideas for improving seq_along:
>
> * It would be really useful to have a second argument dim:
>
> seq_along(mtcars, 1)
> seq_along(mtcars, 2)
> # equivalent to
> seq_len(dim(mtcars)[1])
> seq_len(dim(mtcars)[2])
>
> I often find myself wanting to iterate over the rows or column of a
> data frame, and there isn't a particularly nice idiom if you want to
> avoid problems with zeros - you have to use seq_len(nrow(df)) etc

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

Duncan Murdoch

>
> * To me, it would seem be very natural to have a rep_along function:
>
> rep_along<- function(x, y) rep(x, length.out = length(y))
>
> possibly with more checking for the case where the lengths aren't
> integer multiples.
>
> I'd be happy to submit proposed implementations/documentation if there
> was interest.
>
> Hadley
>



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Fri 06 Jan 2012 - 19:40:11 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 06 Jan 2012 - 20:10:07 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive