[R] allequal diff

Ivan Krylov |kry|ov @end|ng |rom d|@root@org
Fri Aug 16 10:50:44 CEST 2024


В Fri, 16 Aug 2024 10:35:35 +0200
<sibylle.stoeckli using gmx.ch> пишет:

> what do you mean by use is.na() in getValues(). So I need to call
> getValues a second time?

Not necessarily, but it's one of the options. I was thinking along the
lines of:

values1 <- getValues(r1)
mask1 <- is.na(values1)
# Do the same for r2
# Combine the masks
all.equal(values1[!combined_mask], values2[!combined_mask])

Unlike compareRaster(), this assumes that the coordinate grid of r1 and
r2 is already the same and that only some of the values may differ.

> I suppose you mean to first prepare a mask using is.na without
> getValues and then in the second step your code?  

'raster' documentation says that is.na() works on raster objects, so it
should work.

Even if it didn't work, since you already access the underlying data
using getValues() and then compare the resulting vectors using
all.equal(), using is.na(getValues(...)) should definitely work.

-- 
Best regards,
Ivan



More information about the R-help mailing list