Question

I have been using this function for a while now. It is weird that all of the sudden the fun=mean is not working for raster package of R!!

rasterize(data_r[,1:2], r, data_r[,3], fun=mean)

Error in .pointsToRaster(x, y, field = field, fun = fun, background = background,  : 
  could not find function "fun"

However, anything other than mean is working; e.g. fun = 'sum' seems to work fine! Any idea?

Was it helpful?

Solution

Works fine here:

Rgames> rasterize(matrix(1:6,3)/6,raster(matrix(1:8,4)/8),fun=mean)
class       : RasterLayer 
dimensions  : 4, 2, 8  (nrow, ncol, ncell)
resolution  : 0.5, 0.25  (x, y)
extent      : 0, 1, 0, 1  (xmin, xmax, ymin, ymax)
coord. ref. : NA 
data source : in memory
names       : layer 
values      : 1, 3  (min, max)

Did you check to be sure you haven't accidentally removed mean from your environment, or overwritten it w/ something else?

OTHER TIPS

If you have accidentally created another function with the name mean, you can still access the original function in its namespace, i.e., base, using base::mean.

rasterize(data_r[,1:2], r, data_r[,3], fun = base::mean)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top