Dear Ben
Many thanks.
I see that a second challenge are NA values. Is it possible to consider
na.rm=TRUE?
> r2_resampled <- resample(r2, r1)
> compareRaster(r1, r2_resampled)
[1] TRUE
>
> all.equal(getValues(r1), getValues(r2_resampled), tolerance = 0)
[1] "'is.NA' value mismatch: 9544032 in current 66532795 in
target"
Kind regards
Sibylle
-----Original Message-----
From: R-help <r-help-bounces at r-project.org> On Behalf Of Ben Bolker
Sent: Friday, August 16, 2024 1:06 AM
To: r-help at r-project.org
Subject: Re: [R] allequal diff
Digging into the code for raster::compareRaster():
library(raster)
r <- raster(ncol=3, nrow=3)
values(r) <- 1:ncell(r)
r2 <- r
values(r2) <- c(1:8,10)
all.equal(getValues(r), getValues(r2), tolerance = 0) [1] "Mean relative
difference: 0.1111111"
compareRaster has fancier machinery internally for doing the comparison for
large rasters a block at a time if everything can't fit in memory at the
same time ...
On 2024-08-15 9:14 a.m., SIBYLLE ST?CKLI via R-help wrote:
> Dear community
>
>
>
> Similar to the example of the rdocumentation, my idea is to use
> all.equal and to print the difference.
>
>
<https://www.rdocumentation.org/packages/base/versions/3.6.2/topics/all>
https://www.rdocumentation.org/packages/base/versions/3.6.2/topics/all
> .equal
>
>
>
>> d45 <- pi*(1/4 + 1:10)
>
>> stopifnot(
>
> + all.equal(tan(d45), rep(1, 10))) # TRUE, but
>
>> all (tan(d45) == rep(1, 10)) # FALSE, since not exactly
>
> [1] FALSE
>
>> all.equal(tan(d45), rep(1, 10), tolerance = 0) # to see difference
>
> [1] "Mean relative difference: 1.29526e-15"
>
>>
>
>
>
> Unfortunately, I just get "FALSE" not the difference.
>
>> r2_resampled <- resample(r2, r1)
>
>> compareRaster(r1, r2_resampled)
>
> [1] TRUE
>
>> # Compare rasters
>
>> result <- all.equal(r1, r2_resampled)
>
> Warning message:
>
> In compareRaster(target, current, ..., values = values, stopiffalse =
> stopiffalse, :
>
> not all objects have the same values
>
>> print(result)
>
> [1] FALSE
>
>>
>
>
>
> Kind regards
>
> Sibylle
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> <mailto:R-help at r-project.org> R-help at r-project.org mailing
list -- To UNSUBSCRIBE and more, see
> <https://stat.ethz.ch/mailman/listinfo/r-help>
https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> <http://www.R-project.org/posting-guide.html>
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
--
Dr. Benjamin Bolker
Professor, Mathematics & Statistics and Biology, McMaster University
Director, School of Computational Science and Engineering > E-mail is sent
at my convenience; I don't expect replies outside of working hours.
______________________________________________
<mailto:R-help at r-project.org> R-help at r-project.org mailing list --
To UNSUBSCRIBE and more, see
<https://stat.ethz.ch/mailman/listinfo/r-help>
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
<http://www.R-project.org/posting-guide.html>
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
[[alternative HTML version deleted]]