[Rd] seq_along and rep_along

From: Hadley Wickham <hadley_at_rice.edu>
Date: Fri, 06 Jan 2012 12:31:55 -0600

Hi all,

A couple of ideas for improving seq_along:

    seq_along(mtcars, 1)
    seq_along(mtcars, 2)
    # equivalent to


  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

  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.


Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University

R-devel_at_r-project.org mailing list
Received on Fri 06 Jan 2012 - 18:37:03 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:00: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