1

I want to repeat a factor as illustrated below: I am not sure if this can be done using the rep() function?

input:

c("100G","105G","302G")

out:

c("100G","100G","100G","100G","100G","105G","105G","105G","105G","105G","302G","302G","302G","302G","302G")
user2300940
  • 2,355
  • 1
  • 22
  • 35
  • 4
    The `rep` can take a couple of options i.e. either `each` or `times` If we are going to use `times`, the length should be the same as the initial vector. `rep(v1, times = c(5, 6, 7))` – akrun Apr 05 '16 at 10:29

2 Answers2

2

It can be done as:

inputVec <- c("100G","105G","302G")
outputVec <- rep(inputVec, each = 5)
outputVec
Kumar Manglam
  • 2,780
  • 1
  • 19
  • 28
2

Yes, this can be done ...

This should do the trick:

rep(c("100G","105G","302G"), each=10)
petermeissner
  • 12,234
  • 5
  • 63
  • 63