[R-sig-Geo] Assign values of empty matrix to a raster layer in R

John Baumgartner johnbaums at gmail.com
Mon Jul 13 01:00:20 CEST 2015


A reproducible example would help us understand your problem, but since
you're working with matrices, this doesn't seem like a raster package (or
more generally, an R-sig-Geo) issue.

mCon is already a matrix - why do you need to assign it to an "empty
matrix" (r4)?

Do you mean an empty raster? If so, r4[] <- mCon should do what you want,
but then if that's the case, using Con(r2< 2, r1, Con(r2>1, r3, 0)) with
*rasters* r1, r2 and r3 should also return the raster you're after.

Cheers,
John



On Mon, Jul 13, 2015 at 3:22 AM, Ashraf Afana <
Ashraf.Afana at 3dlasermapping.com> wrote:

> Hi,
> I'm trying to apply a conditional statement to three raster layers using
> the following function:
>
> Con = function (condition, trueValue, falseValue){
>   return(condition*trueValue + (!condition)*falseValue)
> }
>
> A priori I've generated an empty matrix (r4) that match the other two
> raster layers. Also, I've converted the three rasters to matrix (r1, r2 &
> r3).
> I've create the conditional matrix (mCon):
> mCon = as.matrix(Con1(r2< 2, r1, Con1(r2>1, r3, 0)))
> Everything works perfectly. However, when I try to assign values mCon to
> the empty matrix (r4), I always get the following error message:
> (Error in (function (classes, fdef, mtable):
> unable to find an inherited method for function 'values<-' for signature
> '"matrix"')
>
> Any suggestions of this error and how to sort this out?
> Thanks
> Ashraf,
>
>
>
>         [[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
>

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list