3

I have this vector:

Photoperiod <- c("Day","Sunset","Night","Sunrise")

I would like to create a vector in which Day is repeated 12 times, Sunset 2 twice, Night 8 times and Sunrise twice until I get a vector of length equal to 168.

How could I do this?

Dekike
  • 1,264
  • 6
  • 17

2 Answers2

7

What about:

rep(rep(c("Day","Sunset","Night","Sunrise"), c(12, 2, 8, 2)), length.out = 168)
tmfmnk
  • 38,881
  • 4
  • 47
  • 67
3

Another option using one rep and recycling technique.

x <- character(168)
x[] <- rep(Photoperiod, c(12, 2, 8, 2))
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213