[R] repace values in raster based on values in another raster

sean_parks sean_parks at fs.fed.us
Wed Sep 5 00:58:11 CEST 2012


Hi,

I am attempting to create a new raster based on values of another raster.

In the Arc world, this is called a "conditional statement" or "con
statement".

I am having quite a bit of difficulty figuring this out in R.

Here is some pseudo-code:
if (fire.did.not.occurr == 1)
then (new. raster = landuse.raster)

Here is some real code and the associated error:
> landuse.raster <- raster("C:/temp/landuse.raster.tif")
> new.raster <- landuse.raster
> new.raster[new.raster > 0] <- NA 
> new.raster[fire.did.not.occurr == 1] <- landuse.raster
Error in x at data@values[i] <- value : 
  incompatible types (from S4 to integer) in subassignment type fix

If I replace the "landuse.raster" with a specific number in the final
command, then the operation works, but I would like to replace with the
values in the landuse.raster.

Please help.

FYI: Please know that I have searched the forums and have not found anything
helpful. Perhaps I am using incorrect search criteria.

Thanks,
Sean





--
View this message in context: http://r.789695.n4.nabble.com/repace-values-in-raster-based-on-values-in-another-raster-tp4642245.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list