I'm working on a practice test for a final exam I have coming up, and this is one of the questions:
Create the following vector by using both the
rep
andseq
functions:x = -7, -7, -7, 0, 7, 7, 14, 14, 14, 14
I cannot wrap my head around how to create this pattern. Here's what I have so far, but I'm not sure this is the most elegant way to accomplish it:
rep(seq(-7, 14, 7), c(3,1,2,4))
Any suggestions would be greatly appreciated!
Your solution looks elegant enough to me. In your solution, you may want to add a few things to increase readability-
rep(seq(from = -7, to = 14, by = 7), times = c(3,1,2,4))