Thanks Sarah.

The code runs fine but I still dont get 3 different resukts (corresponding
to the 3 zs). Here is what I get instead:

> summary(results[[i]])

Min.    0.5900
1st Qu. 0.5911
Median  0.5917
Mean    0.5918
3rd Qu. 0.5924
Max.    0.5936
> summary (IDWRaster.temp)

Min.    0.5900
1st Qu. 0.5911
Median  0.5917
Mean    0.5918
3rd Qu. 0.5924
Max.    0.5936


#### the code

library(gstat)
library(raster)
x <- 1:10
#y <- 1:10
z<- 1:10
results <- list()
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)
results[[i]] <- IDWRaster.temp
}


Thanks again.
minti
On Tue, Dec 4, 2012 at 6:19 PM, Sarah Goslee <sarah.goslee@gmail.com> wrote:

> I would save the information you're interested in as a list:
>
>
> library(gstat)
> library(raster)
> x <- 1:10
> #y <- 1:10
> z<- 1:10
>
> results <- list()
>
> 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)
>
>
>  # I want to save the results from  IDWRaster.temp
>
> results[[i]] <- IDWRaster.temp
>  }
>
> On Tue, Dec 4, 2012 at 1:15 PM, alemante zd <mintibezabih@gmail.com>
> wrote:
> > Dear R-sig-geo users,
> >
> > I have the following code in a loop. I was wondering how I can get the
> > results saved from the loop. The result I am interested in
> > is  IDWRaster.temp
> >
> > 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)
> >  # I want to save the results from  IDWRaster.temp
> > }
> > Thanks in advance for any help.
> > Miniti
> >
> >         [[alternative HTML version deleted]]
> >
> > _______________________________________________
> > R-sig-Geo mailing list
> > R-sig-Geo@r-project.org
> > https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
>
>
> --
> Sarah Goslee
> http://www.stringpage.com
> http://www.sarahgoslee.com
> http://www.functionaldiversity.org
>

	[[alternative HTML version deleted]]

