[R-sig-Geo] loops in rasterEngine

Boulanger, Yan Yan.Boulanger at RNCan-NRCan.gc.ca
Thu Mar 13 02:55:49 CET 2014


Sorry, now it's much easier to see the code.
yan

Yan Boulanger, Chercheur scientifique / Research scientist 
Ressources Naturelles Canada, Canadian Forest Service 
Centre de Foresterie des Laurentides 
1055, rue du P.E.P.S.
C.P. 10380, succ. Sainte-Foy
Québec (Québec) Canada
G1V 4C7 
Tel. : +1 418 649-6859 


-----Original Message-----
From: r-sig-geo-bounces at r-project.org [mailto:r-sig-geo-bounces at r-project.org] On Behalf Of Boulanger, Yan
Sent: 12 mars 2014 20:52
To: r-sig-geo at r-project.org
Subject: [R-sig-Geo] loops in rasterEngine

Hi folks,

I guess I have a lot to learn to write functions but I'm stuck when using rasterEngine. It seems that it should be very easy to do but I'm missing something, apparently... I have a raster, Safranyik_zones_1961_1990, with values (integer) from 1 to 5. I would like to create five rasters for which value will be 1 when the raster Safranyik_zones_1961_1990 is equal to "i", and NA otherwise. I would like to run everything in a loop . Here's what I thought would be ok.

fun_zone <- function(Safranyik_zones,i,...) { 

Safranyik_zonesb <- Safranyik_zones Safranyik_zonesb[] <- NA 

Safranyik_zonesb[Safranyik_zones == i] <- 1

return(Safranyik_zonesb)

}

for (i in 1:5){

Safranyik_zones_1961_1990b <- rasterEngine(Safranyik_zones=Safranyik_zones_1961_1990,i=i, fun=fun_zone) 

assign(paste("Safranyik_zones_1961_1990b_",i, sep=""),Safranyik_zones_1961_1990b[[1]])

}

Of course, it says that « i » is missing...:

>Erreur dans Safranyik_zones == i : 'i' est manquant

Any help?

Thanks in advance,

Yan


Yan Boulanger, Chercheur scientifique / Research scientist Ressources Naturelles Canada, Canadian Forest Service Centre de Foresterie des Laurentides 1055, rue du P.E.P.S.
C.P. 10380, succ. Sainte-Foy
Québec (Québec) Canada
G1V 4C7
Tel. : +1 418 649-6859




	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list