[R] Repeat elements of character vector

Knut Hansen knut.hansen at uit.no
Fri Jan 30 14:34:17 CET 2015


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", "c_1", "c_2", "c_3")

Knut Hansen
knut.hansen at uit.no



More information about the R-help mailing list