R terra resample method="med" not working

Viewed 18

I try to use resample in terra with a median method and I get the following message "Error: [resample] " . Other methods works fine :

library(terra)
x <- rast( xmin=0, xmax=200, ymin=0, ymax=200,crs="epsg:2948", resolution=20)
y <- rast( xmin=0, xmax=200, ymin=0, ymax=200,crs="epsg:2948", resolution=10)
values(x)<-runif(100)
resample(x,y,method="q1")  # works fine
resample(x,y,method="med")  # not working
1 Answers

You do not report the version of "terra" that you are using, nor the error message that you get, but with the current (CRAN) version of terra I get:

library(terra)
#terra 1.6.17
x <- rast(xmin=0, xmax=200, ymin=0, ymax=200,crs="epsg:2948", resolution=20)
y <- rast(xmin=0, xmax=200, ymin=0, ymax=200,crs="epsg:2948", resolution=10)
values(x) <- runif(100)
resample(x,y,method="med") 

#class       : SpatRaster 
#dimensions  : 20, 20, 1  (nrow, ncol, nlyr)
#resolution  : 10, 10  (x, y)
#extent      : 0, 200, 0, 200  (xmin, xmax, ymin, ymax)
#coord. ref. : NAD83(CSRS) / MTM zone 6 (EPSG:2948) 
#source      : memory 
#name        :      lyr.1 
#min value   : 0.01575427 
#max value   : 0.99837255 
 

So it seems that you are using an older version and that you should update the "terra" package with install.packages("terra")

Related