[R] question for loop on matrix row level.
Spencer Graves
spencer.graves at pdf.com
Wed Aug 20 04:05:27 CEST 2003
Have you considered making "aval" an array with the same number of
columns as "matrixname"? Try the following:
aval <- array(NA, dim=c(2,2))
for(i in 1:2){
matrixname <- array(i+(1:4), dim=c(2,2))
aval[i,] <- matrixname[1,]
}
aval
hope this helps. spencer graves
Lily wrote:
> For the 1000 simulations, a matrix will be generated
> each time. And, I need to choose the first row of the
> generated matrix. The following loop doesn't work
> though:
>
> for (i in 1:1000) {
>
> aval[i]<- matrixname[1,]
>
> }
>
> Any solution? thanks!
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
More information about the R-help
mailing list