Thank you Etienne and Steven for your suggestions. I tried the ordinary matrix method as suggested by Etienne. It works fine. It was fast and produced excellent results for my original raster files with 10 values.
Steven, when I try to incorporate more number of cell values, the procedure is getting longer as I have to reclassify multiple times for different combinations. Best regards, On Thu, Oct 18, 2012 at 1:50 AM, steven mosher <mosherste...@gmail.com> wrote: > > reclassify r1 to 1 and 0. reclassify r2 to 0 1 and 2. > then multiply the rasters. > so r1 becomes 0 for all values ecept 1. r2 is 1 or 2 or 0. and the product r3 > will be 1 or 2 or 0 > > On Oct 17, 2012 11:55 AM, "aniruddha ghosh" <aniru...@gmail.com> wrote: >> >> Dear List, >> I have two raster layers (r1 and r2) and the cells have values ranging 1 to >> 10. I want to create a new raster layer from these two with different >> conditions like: >> 1) if r1==1 and r2==1, then r3 should be 1 >> 2) if r1==1 and r2==2, then r3 should be 2 >> else 0 etc >> >> With the following example: >> >> m1<-matrix(c(1,1,1,2,2,2,3,3,3),ncol=3,byrow=TRUE) >> m2<-matrix(c(1,2,1,1,2,3,2,3,3),ncol=3,byrow=TRUE) >> r1<-raster(m1) >> r2<-raster(m2) >> Here, r1[1,1]=1 and r2[1,1]=1, so for the new raster, [1,1] should be 1, >> r1[1,2]=1 and r2[1,2]=2, so for the new raster, [1,2] should be 2, >> all other cells which don't satisfy the above criteria should be zero. >> >> I tried with "calc" in raster package but the attempt was not successful. >> >> Looking forward to your suggestions! >> >> >> Thanks >> -- >> Ani >> >> [[alternative HTML version deleted]] >> >> _______________________________________________ >> R-sig-Geo mailing list >> R-sig-Geo@r-project.org >> https://stat.ethz.ch/mailman/listinfo/r-sig-geo -- Ani _______________________________________________ R-sig-Geo mailing list R-sig-Geo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo