[R] A question about for loop
Moohwan Kim
kmhlmj2 at gmail.com
Fri Aug 18 07:31:40 CEST 2017
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 I want to get is:
[1] 1 1 1 1 1 1 1
[1] 1
[1] 1 1 1 1 1 1 1
[1] 1
How could I get the desired outcome?
best,
kmh
[[alternative HTML version deleted]]
More information about the R-help
mailing list