> 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 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
[email protected]
______________________________________________
[email protected] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
______________________________________________
[email protected] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.