I want to create a sequence of non-integer values where each value is repeated a certain number of times in R. I've tried combining variations of:
seq(5,0,by=-0.5)
which returns
# [1] 5.0 4.5 4.0 3.5 3.0 2.5 2.0 1.5 1.0 0.5 0.0
as well as
rep(5:0,each=3)
which returns
# [1] 5 5 5 4 4 4 3 3 3 2 2 2 1 1 1 0 0 0
each of which contains partly what I want, which would look like this:
5 5 5 4.5 4.5 4.5 4 4 4 3.5 3.5 3.5 3 3 3 2.5 2.5 2.5 2 2 2 1.5 1.5 1.5 1 1 1 0.5 0.5 0.5 0 0 0
It seems that seq() contains no "each" analogue, whereas rep() contains no "by" argument. Anyone know of a third function that can do both, or a way to combine these two to accomplish my goal? Or, another way alltogether?
Just combine!
rep(seq(5,0,by=-0.5), each=3)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With