4

I know I've accomplished this before, but I'm just not figuring it out again! Here's the vector I want to produce with the rep() function:

> myvec    
> A1   A1   B1   B1   B1   B1

I know how to use each to produce A1 and B1 the same number of times: rep(c("A1", "B1"), each = 2). But how do I specify different values for each to repeat A1 twice and B1 three times?

user8121557
  • 149
  • 2
  • 9

1 Answers1

7

Although it is a little counterintuitive the following works:

> rep(c("A1", "B1"), times = c(2, 3))
[1] "A1" "A1" "B1" "B1" "B1"
vonjd
  • 4,202
  • 3
  • 44
  • 68