[R-sig-Geo] Error message in calc()

2013-10-07 Thread Eddie Smith
Dear list, I have a RasterLayer as follows class : RasterLayer band: 1 (of 365 bands) dimensions : 1032, 1656, 1708992 (nrow, ncol, ncell) resolution : 0.0417, 0.0417 (x, y) extent : 96.5, 165.5, -16.5, 26.5 (xmin, xmax, ymin, ymax) coord. ref. : +proj=longlat

Re: [R-sig-Geo] Error message in calc()

2013-10-07 Thread GD
For RasterLayer objects, I think you need to use 'maxValue' and 'minValue' instead of max and min -- View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Error-message-in-calc-tp7584795p7584796.html Sent from the R-sig-geo mailing list archive at Nabble.com.

Re: [R-sig-Geo] Error message in calc()

2013-10-07 Thread GD
Apologies the last suggestion was totally wrong, since 'calc' applies the function to each cell (represented as a vector). However, the problem might be that the 'which' function inside your 'fun1' is sometimes returning more than one value. In that case, you might try forcing 'w' to have the

Re: [R-sig-Geo] Error message in calc()

2013-10-07 Thread Robert J. Hijmans
The problem, I think, is that there are NA values on your raster. You have not considered the effect of NA values on what is returned by fun1. You can fix fun1, but in this case I would do: library(raster) s - stack(system.file(external/rlogo.grd, package=raster)) s[1:10] - NA m - max(s) w -