[R-sig-Geo] Error message in calc()
Robert J. Hijmans
r.hijmans at gmail.com
Mon Oct 7 13:44:23 CEST 2013
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 <- which.max(s)
Robert
On Mon, Oct 7, 2013 at 2:29 AM, Eddie Smith <eddieatr at gmail.com> wrote:
> Dear list,
>
> I have a RasterLayer as follows
>
> class : RasterLayer
> band : 1 (of 365 bands)
> dimensions : 1032, 1656, 1708992 (nrow, ncol, ncell)
> resolution : 0.04166667, 0.04166667 (x, y)
> extent : 96.5, 165.5, -16.5, 26.5 (xmin, xmax, ymin, ymax)
> coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84
> +towgs84=0,0,0
> data source : ...\2012.tif
> names : X2012
> values : 16.75, 34.35 (min, max)
>
>
> I tried to extract the annual maximum image using :
> fun1 <- function(x){
> m <- max(x)
> w <- which(max(x) == x)
> return(c(m, w))
> }
> s2 <- calc(stack, fun = fun1)
>
> but end up with this error message :
> Error in setValues(out, x) :
> values must be numeric, integer, logical or factor
>
> I am not sure where I went wrong as the min and max values are 1.75 and
> 34.35.
>
> Anybody?
>
> Thanks in advance.
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
More information about the R-sig-Geo
mailing list