My aim was to get the dominant land cover class for a given area using the terra package.
In principle, this can be done with the function extract as for example
library(terra)
library(rworldmap)
r <- rast(nrows=10, ncols=10)
values(r) <- sample(3, ncell(r), replace=TRUE)
worldMap <- getMap()
terra::extract(x, map,fun=max)
The problem with this approch, the landcover with the highest numeric value will be selected, and not the dominant class. How to sort this?