What version of raster are you using? I don't get your behavior. I've tried
this on R 2.13.2 and R 2.14 (two different versions of raster).

> a <- c(1,1,1,0,0,0,2,2,2)
> a <- matrix(a,3,3,byrow=T)
> a <- raster(a)
> a []
[1] 1 1 1 0 0 0 2 2 2
> b <- 10 - a
> b[]
[1]  9  9  9 10 10 10  8  8  8

------------------------------------------------------
R version 2.13.2 (2011-09-30)
Platform: x86_64-pc-mingw32/x64 (64-bit)

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] raster_1.8-9 sp_0.9-91    rj_1.0.0-3

loaded via a namespace (and not attached):
[1] grid_2.13.2     lattice_0.19-33 rj.gd_1.0.0-1   tools_2.13.2
------------------------------------------------------

R version 2.14.0 (2011-10-31)
Platform: x86_64-pc-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=Slovenian_Slovenia.1250  LC_CTYPE=Slovenian_Slovenia.1250
[3] LC_MONETARY=Slovenian_Slovenia.1250 LC_NUMERIC=C
[5] LC_TIME=Slovenian_Slovenia.1250

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] raster_1.9-33 sp_0.9-91     rj_1.0.0-3

loaded via a namespace (and not attached):
[1] grid_2.14.0    lattice_0.20-0 rj.gd_1.0.0-1  tools_2.14.0




Cheers,
Roman



On Tue, Nov 1, 2011 at 4:40 PM, Aidin Niamir <niamir@gmail.com> wrote:

> Dear all
>
> I am experiencing a strange problem when calculating in the raster package.
> Let me explain it with a simple example;
>
> > a <- c(1,1,1,0,0,0,2,2,2)
> > a <- matrix(a,3,3,byrow=T)
> > a <- raster(a)
> > a []
> [1] 1 1 1 0 0 0 2 2 2
> > b <- 10 - a
> > b []
> [1]  -9  -9  -9 -10 -10 -10  -8  -8  -8
>
> As you can see, the obtained values are not correct. I cannot see why
> this should be.
> Can anybody help?
>
> Aidin Niamir
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>



-- 
In God we trust, all others bring data.

	[[alternative HTML version deleted]]

