Hi, I just replied to Alessandro off-list, but having see your reply, I thought I might as well go on list with my answer/question...
I think a slight adaptation is still required: cp <- paste(sep="","centre_plot",i) should be cp <- as.data.frame(get(paste("centre_plot",i,sep=""))) or coordinates(cp) should be coordinates(as.data.frame(get(cp)) because the coordinates() function asks for a data.frame object, where get() returns a matrix. Then your get(cp)[z] is unnecessary, if I am right, but the character object for the file names need to be reconstructed. So something like: for(i in 1:500) { cp <- as.data.frame(get(paste("centre_plot",i,sep=""))) coordinates(cp) =~X+Y proj4string(cp) <- CRS("+init=epsg:26911") writeOGR(cp["Z"], paste(paste("centre_plot",i,sep=""), ".shp", sep=""),paste("centre_plot",i,sep=""),driver="ESRI Shapefile") } Hope this works. When I played around with it, it did.... Kami -----Original Message----- From: [EMAIL PROTECTED] on behalf of G. Allegri Sent: Wed 19.11.2008 22:14 To: Alessandro Cc: r-sig-geo@stat.math.ethz.ch Subject: Re: [R-sig-Geo] problem with loop formula in my analysis A correction. cp["Z"] should be get(cp)[z], to evaluate the string to a variable name... 2008/11/19 G. Allegri <[EMAIL PROTECTED]>: > Alessandro, > I suggest to read some startup tutorials before asking in ML. > Anyway you can do this: > > for(i in 1:500){ > cp <- paste(sep="","centre_plot",i) > coordinates(cp) =~X+Y > proj4string(cp) <- CRS("+init=epsg:26911") > writeOGR(cp["Z"], paste(sep="",cp,".shp"), cp,driver="ESRI Shapefile") > } > > > > 2008/11/19 Alessandro <[EMAIL PROTECTED]>: >> Hi All, >> >> I read a lot about loop formula but this morning I tried to applied the loop >> for the following formulas >> >> I know it's easy for an expertise, but sorry I am working with R in this >> mounts and I change completely my GIS philosophy. >> >> >> >> Thanks for help >> >> >> >> give a coordinates attribution >> >> >> >> coordinates(centre_plot1) =~X+Y >> >> coordinates(centre_plot2) =~X+Y >> >> coordinates(centre_plot3) =~X+Y >> >> coordinates(centre_plot4) =~X+Y >> >> ...................... >> >> ..................... >> >> (I HAVE 500 plot) >> >> >> >> proj4string(centre_plot1) <- CRS("+init=epsg:26911") >> >> proj4string(centre_plot2) <- CRS("+init=epsg:26911") >> >> proj4string(centre_plot3) <- CRS("+init=epsg:26911") >> >> proj4string(centre_plot4) <- CRS("+init=epsg:26911") >> >> >> >> writeOGR(centre_plot1 ["Z"], " centre_plot1.shp", " centre_plot1", >> driver="ESRI Shapefile") >> >> writeOGR(centre_plot2 ["Z"], " centre_plot2.shp", " centre_plot2", >> driver="ESRI Shapefile") >> >> writeOGR(centre_plot3 ["Z"], " centre_plot3.shp", " centre_plot3", >> driver="ESRI Shapefile") >> >> writeOGR(centre_plot4 ["Z"], " centre_plot4.shp", " centre_plot4", >> driver="ESRI Shapefile") >> >> >> >> Ale >> >> >> [[alternative HTML version deleted]] >> >> _______________________________________________ >> R-sig-Geo mailing list >> R-sig-Geo@stat.math.ethz.ch >> https://stat.ethz.ch/mailman/listinfo/r-sig-geo >> > _______________________________________________ R-sig-Geo mailing list R-sig-Geo@stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo Click https://www.mailcontrol.com/sr/wQw0zmjPoHdJTZGyOCrrhg== to report this email as spam. The Zoological Society of London is incorporated by Royal Charter Principal Office England. Company Number RC000749 Registered address: Regent's Park, London, England NW1 4RY Registered Charity in England and Wales no. 208728 _________________________________________________________________________ This e-mail has been sent in confidence to the named add...{{dropped:20}} _______________________________________________ R-sig-Geo mailing list R-sig-Geo@stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo