Reputation: 589
I want to create a vector1 that consist of the repetition of each value of another vector2 as many times as the value itself of each element of vector2
V2 <- c(1,3,2)
V1 should be:
c(1,3,3,3,2,2)
Upvotes: 2
Views: 96
Reputation: 887128
We can use rep to do this
rep
rep(V2, V2) #[1] 1 3 3 3 2 2
Upvotes: 4