Skip to content

alternative way to replicate()

5 messages · Liviu Andronic, Dimitris Rizopoulos, Johannes Hüsing +1 more

#
Dear all,

I'm looking for an alternative way to replicate the "2," string for an
x number of times, and end up with one string containing "2," x times.
I can partly achieve this using replicate().
[1] "2," "2," "2,"

The output that I am looking for is, however, "2,2,2,". I also tried
to append(), with similar (unsatisfactory) results.
+ z <- append(z, y[i])}
[1] "2," "2," "2,"

Could anyone suggest how "2," can be replicated to "2,2,2,"?
Thank you,
Liviu
#
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 = "")


I hope it helps.

Best,
Dimitris
Liviu Andronic wrote:

  
    
#
Am 03.12.2008 um 09:06 schrieb Liviu Andronic:
JFTR: replicate() is a different function from rep(). See ?rep and 
?replicate.
#
Thanks all. All solutions are usable. These two I received off-list:
[1] "2, 2, 2"

and
Liviu


On Wed, Dec 3, 2008 at 9:14 AM, Dimitris Rizopoulos
<d.rizopoulos at erasmusmc.nl> wrote:
4 days later
#
Is this what you want:
[1] "2,2,2,2,2"

        
On Wed, Dec 3, 2008 at 5:36 AM, Johannes H?sing <johannes at huesing.name> wrote: