Re: [Rd] 'data.frame' method for base::rep()

From: Martin Maechler <>
Date: Wed, 03 Aug 2011 14:44:20 +0200

>>>>> David Winsemius <> >>>>> on Tue, 2 Aug 2011 10:14:59 -0400 writes:

    > On Aug 2, 2011, at 7:55 AM, Liviu Andronic wrote:

>> Dear R developers Would you consider adding a
>> 'data.frame' method for the base::rep function? The need
>> to replicate a df row-wise can easily arise while
>> programming, and rep() is unable to handle such a
>> case. See below.

    >>> x <- iris[1, ]


    > x[ rep(1,2), ] # "works"

Yes, indeed, and that I think is my "definitive" answer to the proposal.
Defining a rep() method for data frames seems much less sensible First because one simple "substitute" exists (namely indexing, see above), and to me, not the least because there are several problems / questions that would have to be answered

  --> and of course, the indexing solution

     xx <- iris[ rep(1:nrow(iris), 3) , ]  

  does implement one sensible way of producing unique row.names,   {though, I must say, not the "optimal" one if the issue is efficiency}

Rather keep using [,] and let's not get into having to maintain yet another data.frame method ..

Martin Maechler, ETH Zurich mailing list Received on Wed 03 Aug 2011 - 12:47:16 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 Wed 03 Aug 2011 - 13:20:14 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive