-1

I have a vector called samples which is the following:

my_samples = c("16S-P030N" ,"16S-P034N", "16S-P035N")

I need to create a vector of each value repeated 30 times so what I usually do is the following:

rep_samples_vector = c(rep("16S-P030N",30),rep("16S-P034N",30), rep("16S-P035N",30))

The problem is that I have near 50 samples, so is there a way to do this in a faster way in R ? I was thinking on using a for loop but I don't have clea1r how to do that in R?

Valentin
  • 399
  • 2
  • 10

1 Answers1

0

The rep() function has an each= attribute that will do what you want:

my_samples = c("16S-P030N" ,"16S-P034N", "16S-P035N")
rep(my_samples,  each=30)
M.Viking
  • 5,067
  • 4
  • 17
  • 33