[R] Alternate looping

Patrick Connolly p_connolly at slingshot.co.nz
Tue Jan 6 20:10:21 CET 2009


On Tue, 06-Jan-2009 at 04:27PM +0000, Luis Ridao Cruz wrote:

|> R-help,
|> 
|> I'm using the "for" control flow to graph plots continuously:
|> 
|> par(mfrow=c(3,5), mar=c(0.6,.2,1.2,.2),yaxt="n",xaxt="n")   
|> for(j in 1:11)  
|> {
|> for(i in 1:15)  
|> {
|> 
|> species <- spAldur[spAldur$ar == 1993+i & spAldur$aldur == j,]
|> 
|> plot(species at coords[,1], species at coords[,2], xlim=c(-10,-3.5),
|> ylim=c(60.1,63)
|> , col=3,type="n",xlab="",ylab="")
|> points(geoFeatures[["dyp100"]],pch=".",cex=1.2,col="blue")
|> .....
|> .....
|> .....
|> }}
|> 
|> This will plot a map of "something" in the following way:
|> 
|> (j=1, i=1), (j=1, i=2),(i=1, i=3),,,,,,,
|> (j=2, i=1), (j=2, i=2),(i=2, i=3),,,,,,,
|> (j=3, i=1), (j=3, i=2),(i=3, i=3),,,,,,,
|> 
|> and so on but I wish to have it like this:
|> 
|> (j=1, i=1), (j=2,i=2),(i=3,i=3),,,,,,,


So what do you do for i > 11?

It might be as simple as a single loop and this:

 species <- spAldur[spAldur$ar == 1993+i & spAldur$aldur == i,]


HTH

-- 
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.   
   ___    Patrick Connolly   
 {~._.~}                   Great minds discuss ideas    
 _( Y )_  	         Average minds discuss events 
(:_~*~_:)                  Small minds discuss people  
 (_)-(_)  	                      ..... Eleanor Roosevelt
	  
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.




More information about the R-help mailing list