Thanks Alex. The code worked but when I added a line in order to save the results but instead of the different z vallues, I only get one value in the results. Here is what I did (it is the same code and the the line I added is: result2 <- as.data.frame(as(IDWRaster.temp, "SpatialGridDataFrame")) ####
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)) { 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) result2 <- as.data.frame(as(IDWRaster.temp, "SpatialGridDataFrame")) #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) } thanks again minti On Mon, Dec 3, 2012 at 7:00 AM, Alexandre Villers < villers.alexan...@gmail.com> wrote: > Hi, > > Sorry, I forgot to close the ( in the for (i in 1: length(y.list)*)* { > Cheers > > Alex > > > 2012/12/2 alemante zd <mintibeza...@gmail.com> > >> 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) { >> 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.alexan...@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 >> >> >> > > > -- > Alexandre Villers, PhD. > Postdoctoral researcher > Section of Ecology > University of Turku > FIN-20014 Turku, Finland > > Phone +358 (0)2 333 5039 > > > > [[alternative HTML version deleted]] _______________________________________________ R-sig-Geo mailing list R-sig-Geo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo