Cool thanks
# values and mask r1
r1 <- getValues(r1)
mask1 <- is.na(r1)
# Do the same for r2
r2 <- getValues(r2_resampled)
mask2 <- is.na(r2)
# Combine the masks
all.equal(r1[!(mask1 & mask2)], r2[!(mask1 & mask2)])
output> all.equal(r1[!(mask1 & mask2)], r2[!(mask1 & mask2)])
[1] "'is.NA' value mismatch: 389 in current 56989152 in
target"
--> so there is just a mismatch in NA not in the xy pixels, right?
Sibylle
-----Original Message-----
From: Ivan Krylov <ikrylov at disroot.org>
Sent: Friday, August 16, 2024 10:51 AM
To: sibylle.stoeckli at gmx.ch
Cc: 'SIBYLLE ST?CKLI via R-help' <r-help at r-project.org>
Subject: Re: [R] allequal diff
? Fri, 16 Aug 2024 10:35:35 +0200
<sibylle.stoeckli at 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