I am confused that how to generate a series (like this 1,2,2,3,3,3,4,4,4,4
) in R.
I use the for loop
and rep
function like this,
for (i in 1:10)
{rep(i,i)}
but I can't paste them together.
rep(1:4, 1:4)
[1] 1 2 2 3 3 3 4 4 4 4
Similarly for another series we get
rep(1:5, 1:5) * (-1)^rep(0:4, 1:5)
[1] 1 -2 -2 3 3 3 -4 -4 -4 -4 5 5 5 5 5
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