Dear Damien, 

> -----Original Message-----
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of damien landais
> Sent: Friday, June 26, 2009 11:16 AM
> To: R-help@r-project.org
> Subject: [R] to raise in a loop more than 1
> 
> 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
> ...
> 

I am not exactly sure what you want. If my guess is correct, this will
reproduce the desired output:

x <- seq(from=0, to=10, by=2)
y <- seq(from=0, to=20, by=4)
z <- seq(from=0, to=10, by=2)

mydata2 <- expand.grid(x=as.factor(x), y=as.factor(y), z=as.factor(z))
mydata3 <- with(mydata2,
                mydata2[order(x,y,z),]
                )
head(mydata3, n=8)


Hope this helps,
Roland

----------
This mail has been sent through the MPI for Demographic Research.  Should you 
receive a mail that is apparently from a MPI user without this text displayed, 
then the address has most likely been faked. If you are uncertain about the 
validity of this message, please check the mail header or ask your system 
administrator for assistance.

______________________________________________
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.

Reply via email to