I have to do variable transfer from an array to a matrix. the function I need is
int i = 1;
for (r in 1:S)
for (c in 1:S){
if (r != c){
beta[r, c] = phi[i];
i += 1;
}
}
Please tell me what is the proper syntax to use inside a parameter block.
Only variable declarations are allowed inside the parameters
block.
If you want to move parameters from an array to a matrix, use the transformed parameters
block.
The condition r != r
in the code you wrote is not ever going to be true, but assuming your data was stored in an array with row major order of the necessary size, then I think what you wrote is headed in the right direction (I don’t think you should have any if statement though).
int i = 1;
for (r in 1:S)
for (c in 1:S){
if (r != r) { // <-- This is never going to be true, don't think it's necessary anyway
beta[r, c] = phi[i];
i += 1;
}
}
1 Like
my bad with the typo. it should be
if (r != c)
Thanks for the comment.
That would not copy the diagonal, but then you’d have to build phi[i] to accomodate that. Totally possible, fwiw.