[R] alternative way to replicate()

Liviu Andronic landronimirc at gmail.com
Wed Dec 3 14:15:51 CET 2008


Thanks all. All solutions are usable. These two I received off-list:
> toString(paste(rep("2",3), sep=","))
[1] "2, 2, 2"

and
> paste(rep("2,",3),collapse="")

Liviu


On Wed, Dec 3, 2008 at 9:14 AM, Dimitris Rizopoulos
<d.rizopoulos at erasmusmc.nl> wrote:
> have a look at ?paste(), e.g.,
>
> paste(rep(2, 3), collapse = ",")
>
> and if you need a comma at the end, then you can again use paste(),
>
> paste(paste(rep(2, 3), collapse = ","), ",", sep = "")
>



More information about the R-help mailing list