Re: [R] A question about for loop

2017-08-18 Thread Boris Steipe
There are many ways to get the output you want, so your question is ill defined. But it is easy to see where your code goes wrong. And it should be easy for you to fix it. If you subset a vector with the '[' operator, this is like putting a vector of indices "into" the square brackets. So, to

[R] A question about for loop

2017-08-17 Thread Moohwan Kim
Dear R users, I have the following codes: zeta <- rep(1,8) n <- 7 for (i in 1:2){ beta <- zeta[1:n+(i-1)*(n+1)] print(beta) parm <- zeta[i*(n+1)] print(parm) } ### The output is as follows: [1] 1 1 1 1 1 1 1 [1] 1 [1] NA NA NA NA NA NA NA [1] NA ### The outcome