[R-sig-Geo] repeated commands... how to loop?
Edzer Pebesma
edzer.pebesma at uni-muenster.de
Sun Dec 2 22:26:32 CET 2012
On 12/02/2012 09:53 PM, alemante zd wrote:
> Thanks Alexandre. Sorry my coding was a bit confusing but I have rectified
> it now. When I run it however, I get error message. The new code and the
> error message I get are as follows:
>
> library(gstat)
> library(raster)
> x <- 1:10
> #y <- 1:10
> z<- 1:10
> setwd("f:/Grids")
> r2 <- raster("idgd_wgs.asc")
>
> z.list <- list(z1<-runif(10), z2 <- runif(10), z3 <- runif(10))
> da1<-data.frame(x=1:10, y=1:10)
> for i in 1:length(z.list) {
for (i in 1:length(z.list))
> da.temp<-data.frame(da1, z=z.list[[i]])
> IDW.temp <- gstat(id = "z", formula = z~1, locations = ~x+y, data=da.temp,
> set=list(idp =2))
> IDWRaster.temp <- interpolate(r2, IDW.temp)
> #add here one or two command lines to save the objects you want to save,
> or check
> rm(da.temp, IDW.temp, IDWRaster.temp) #remove the temporary elements
> (always safer)
> }
>
>
> ### the error message I got is as follows
>
>> library(gstat)
>> library(raster)
>>
>> x <- 1:10
>> #y <- 1:10
>> z<- 1:10
>> setwd("f:/Grids")
>> r2 <- raster("idgd_wgs.asc")
>>
>>
>> z.list <- list(z1<-runif(10), z2 <- runif(10), z3 <- runif(10))
>> da1<-data.frame(x=1:10, y=1:10)
>>
>> for i in 1:length(z.list) {
> Error: unexpected symbol in "for i"
>> da.temp<-data.frame(da1, z=z.list[[i]])
> Error in data.frame(da1, z = z.list[[i]]) : object 'i' not found
>> IDW.temp <- gstat(id = "z", formula = z~1, locations = ~x+y,
> data=da.temp, set=list(idp =2))
> Error in gstat(id = "z", formula = z ~ 1, locations = ~x + y, data =
> da.temp, :
> object 'da.temp' not found
>> IDWRaster.temp <- interpolate(r2, IDW.temp)
> Error in inherits(model, "gstat") : object 'IDW.temp' not found
> In addition: Warning messages:
> 1: In inherits(model, "gstat") : restarting interrupted promise evaluation
> 2: In inherits(model, "gstat") : restarting interrupted promise evaluation
>> #add here one or two command lines to save the objects you want to save,
> or check
>> rm(da.temp, IDW.temp, IDWRaster.temp) #remove the temporary elements
> (always safer)
> Warning messages:
> 1: In rm(da.temp, IDW.temp, IDWRaster.temp) : object 'da.temp' not found
> 2: In rm(da.temp, IDW.temp, IDWRaster.temp) : object 'IDW.temp' not found
> 3: In rm(da.temp, IDW.temp, IDWRaster.temp) :
> object 'IDWRaster.temp' not found
>> }
> Error: unexpected '}' in "}"
> thanks
> //minti
>
> On Sun, Dec 2, 2012 at 7:58 AM, Alexandre Villers <
> villers.alexandre at gmail.com> wrote:
>
>> Hello,
>>
>> It's not really clear from your message whether y1, y2, y3 are the y part
>> of x/y coordinates, and
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
--
Edzer Pebesma
Institute for Geoinformatics (ifgi), University of Münster
Weseler Straße 253, 48151 Münster, Germany. Phone: +49 251
8333081, Fax: +49 251 8339763 http://ifgi.uni-muenster.de
http://www.52north.org/geostatistics e.pebesma at wwu.de
More information about the R-sig-Geo
mailing list