Repeat a vector n times



Question 1: I’m trying to repeat a row_vector n times using:

model {
row_vector[2] myvector = [1,2];
row_vector[6] myvector2;

myvector2 = rep_row_vector(myvector, 3)

I get:
No matches for:

rep_row_vector(row vector, int)

Available argument signatures for rep_row_vector:

rep_row_vector(real, int)

Question 2: I suppose the above performs the equivalent in R to rep(c(1,2),times = 3). How about rep(c(1,2), each = 3) in Stan?

Thanks in advance.


There isn’t a rep_ function to copy a (row) vector into a longer (row) vector. You could do something like

row_vector[6] = append_col(append_col(my_vector, my_vector), my_vector);
1 Like

Thank you @bgoodri for your quick answer. Any alternative to repeat each element of vector n times as in R rep(my_vector, each = n) ?


You would have to just do a loop.

1 Like