For loops, looping through variables

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

For loops, looping through variables

Gary  Nobles
I'm trying to loop through variables.
I have:
xy #point location
b1 #circle 1m
b2 #circle 2m
b3 #circle 3m
each are polygons

I want to do the following
r1 <- r1                         #centre circle
r2 <- gDifference(b2,b1)   #middle 'donut'
r3 <- gDifference(b3,b2)   #outside 'donut'

for the B's I have the following:

rn=3  #number of rings
wd=1 #width distance

for(i in seq(wd, rn, wd)){
  assign(paste("b", i, sep = ""), gBuffer(xy, width = wd*i))

for the R's I add in a line:

assign(paste("r", i, sep = ""), gDifference(b3,b2)

but how do I iterate between the b's? e.g. b[i+i],b[i]