[R-sig-Geo] saving results from a loop

Sarah Goslee sarah.goslee at gmail.com
Tue Dec 4 19:19:20 CET 2012


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 at 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 at 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



More information about the R-sig-Geo mailing list