I have vector name: block_sizes=c(3,3,4) and I want to make a list which it has block_sizes[1] number of 1s,block_sizes[2] number of 2s ,and block_sizes[3] of 3s, etc.
In this example, I should give [3,3,4] to my code and get [1,1,1,2,2,2,3,3,3,3].
I wrote the code below, but I don't know why it gives me [0,3,3,3,3]. I think it is because I should have appended to last element of vector which I am not now. Any input is appreciated.
vector=0
for (i in length(block_sizes )) {
buf=rep.int(i,times =block_sizes[i])
membership_vector=append(vector,buf)
}```