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

From: Liviu Andronic <landronimirc_at_gmail.com>
Date: Tue, 02 Aug 2011 13:55:01 +0200


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
  Sepal.Length Sepal.Width Petal.Length Petal.Width Species 1 5.1 3.5 1.4 0.2 setosa > rep(x, 2)
$Sepal.Length
[1] 5.1

$Sepal.Width
[1] 3.5

$Petal.Length
[1] 1.4

$Petal.Width
[1] 0.2

$Species
[1] setosa

Levels: setosa versicolor virginica

$Sepal.Length
[1] 5.1

$Sepal.Width
[1] 3.5

$Petal.Length
[1] 1.4

$Petal.Width
[1] 0.2

$Species
[1] setosa

Levels: setosa versicolor virginica

I found a 'rep.data.frame' function in package 'mefa' [2], but I think it would be nice to have it in base R. In any case, the code used by the method is very simple.
> require(mefa)
Loading required package: mefa
mefa 3.2-1 2011-05-13
> mefa:::rep.data.frame
function (x, ...)
as.data.frame(lapply(x, rep, ...))
<environment: namespace:mefa>

And here's the example above:
> rep(x, 2)
  Sepal.Length Sepal.Width Petal.Length Petal.Width Species

1          5.1         3.5          1.4         0.2  setosa
2          5.1         3.5          1.4         0.2  setosa


Please le t me know what you think. Regards Liviu

[1] http://finzi.psych.upenn.edu/R/library/mefa/html/rep.data.frame.html
[2] http://cran.at.r-project.org/web/packages/mefa/index.html

-- 
Do you know how to read?
http://www.alienetworks.com/srtest.cfm
http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader
Do you know how to write?
http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Tue 02 Aug 2011 - 11:57:58 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 Tue 02 Aug 2011 - 14:40:13 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