Hi,

I need to convert the DN in binary value. I'm using the raster package and
some versions ago this function was working:

r <- raster(ncols=20, nrows=20)

r[] <- as.integer(runif(ncell(r),min=0,max=255))

fun <- function(x) { as.numeric(intToBits(x)[2]) }

r <- calc(r,fun)

After a raster package update I get this error:

Error in dimnames(x) <- dn :
  length of 'dimnames' [2] not equal to array extent

I solve it with this:

for (i in 1:ncell(r)) {

    r[i] <- as.integer(intToBits(r[i])[2])
}

But now is very slow....

Any suggestions?

Thanks,

Alfredo

	[[alternative HTML version deleted]]

