Hi Tim,
Try reclass()


r <- raster(ncol=100, nrow=100)

r[] <- round(runif(ncell(r)) * 10)

class <- matrix(c(0,3.5,0,3.5,10,1),nrow=2,byrow=T)

rc <-reclass(r, class)

rc


HTH,

Simon

--------------------------------
Simon O'Hanlon, BSc MSc
Department of Infectious Disease Epidemiology
Imperial College London
St. Mary's Hospital
London
W2 1PG
________________________________
From: r-sig-geo-bounces@r-project.org [r-sig-geo-bounces@r-project.org] on behalf of Tim Howard [tghoward@gw.dec.state.ny.us]
Sent: 14 June 2012 14:02
To: r-sig-geo@r-project.org
Subject: [R-sig-Geo] continuous raster to binary

All,
I'd like to convert a continuous raster to binary (0, 1). Here's what I've come up with

library(raster)

#build the sample raster
r <- raster(ncol=100, nrow=100)
r[] <- round(runif(ncell(r)) * 10)
#set up a cut point, cut it
ctpts <- c(0,3.5,10)
rc <- cut(r,breaks=ctpts)

#since the result from cut was a raster with values c(1,2), use subs to change to c(0,1)
subdf <- data.frame(from=c(1,2), to=c(0,1))
rs <- subs(rc, subdf, subsWithNA=TRUE)
rs


My questions:
1. Is there a more efficient way? (I'll be doing this to many large rasters)
2. Using 32-bit R, subs bails with a memory error, even if a file is specified (cut runs fine). I can move to 64-bit R on a different machine, but it would be nice to be able to run it on this 32-bit machine. Any suggestions?

Thanks in advance,
Tim

	[[alternative HTML version deleted]]

