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

Ashraf Afana Ashraf.Afana at 3dlasermapping.com
Sun Jul 12 19:22:31 CEST 2015

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?

	[[alternative HTML version deleted]]

More information about the R-sig-Geo mailing list