Re: [R] Repeat elements of character vector

2015-02-01 Thread PIKAL Petr
2015 2:34 PM > To: r-help@r-project.org > Subject: [R] Repeat elements of character vector > > I have a vector of several character elements: > v1 <- c("a", "b", "c") > > I want each of these elements to be repeated n times and the number of &g

Re: [R] Repeat elements of character vector

2015-01-30 Thread Ivan Calandra
Hi, Take a look at the argument "each" from rep(). You could do that (there might be something shorter): paste(rep(v1,each=3), 1:3, sep="_") HTH, Ivan -- Ivan Calandra, ATER University of Reims Champagne-Ardenne GEGENAA - EA 3795 CREA - 2 esplanade Roland Garros 51100 Reims, France +33(0)3 26

Re: [R] Repeat elements of character vector

2015-01-30 Thread Chel Hee Lee
> paste(rep(v1, each=3), 1:3, sep="_") [1] "a_1" "a_2" "a_3" "b_1" "b_2" "b_3" "c_1" "c_2" "c_3" > Is this what you are looking for? I hope this helps. Chel Hee Lee On 1/30/2015 7:34 AM, Knut Hansen wrote: I have a vector of several character elements: v1 <- c("a", "b", "c") I want each of t

[R] Repeat elements of character vector

2015-01-30 Thread Knut Hansen
I have a vector of several character elements: v1 <- c("a", "b", "c") I want each of these elements to be repeated n times and the number of the repetition added as part of the element text, hence rep() will not work. For n=3 the result would be: v2 <- c("a_1", "a_2", "a_3", "b_1", "b_2", "b_3",