I assume that you are getting this error: > mydata=matrix(nrow=1500,ncol=3) > i=1 > for(x in 0:10){ + for(y in 0:20){ + for(z in 0:10){ + mydata[i,]=c(x,y,z) + i=i+1 + z=z+2} + y=y+4} + x=x+2} Error in mydata[i, ] = c(x, y, z) : subscript out of bounds No suitable frames for recover() > i [1] 1501 > You have indexed outside the limits. For what you are doing, you need the matrix to be 11*21*11=2451
> mydata=matrix(nrow=2541,ncol=3) > i=1 > for(x in 0:10){ + for(y in 0:20){ + for(z in 0:10){ + mydata[i,]=c(x,y,z) + i=i+1 + z=z+2} + y=y+4} + x=x+2} > > head(mydata) [,1] [,2] [,3] [1,] 0 0 0 [2,] 0 0 1 [3,] 0 0 2 [4,] 0 0 3 [5,] 0 0 4 [6,] 0 0 5 > You still don't get what you are expecting because you are trying to change the loop variable within the loop which is not allowed (or really ignored). On Fri, Jun 26, 2009 at 5:15 AM, damien landais <damien.land...@tdf.fr>wrote: > I would raise x,y and z in a loop but I won't raise of 1. I tried this but > it doesn't work > > mydata=matrix(nrow=1500,ncol=3) > i=1 > for(x in 0:10){ > for(y in 0:20){ > for(z in 0:10){ > mydata[i,]=c(x,y,z) > i=i+1 > z=z+2} > y=y+4} > x=x+2} > > And I would have something like that > x y z > 0 0 0 > 0 0 2 > 0 0 4 > 0 0 6 > 0 0 8 > 0 0 10 > 0 4 0 > 0 4 2 > ... > > Could anybody help me? > I don't work on a special package to do it... > > Thanks > > Cordialement > Damien Landais > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. > -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.