library(terra)
r <- rast(ncols=100, nrows=100)
r[] <- round(runif(ncell(r), 1,8), digits=0)
rEnt <- raster.entropy(r, d=5, categorical = TRUE, global = TRUE)
opar <- par(no.readonly=TRUE)
par(mfcol=c(2,1))
plot(r)
plot(rEnt)
par(opar)
# Maximum entropy is reached when all values are different, same as log(m)
# for example; log( length( unique(x) ) )
Run the code above in your browser using DataLab