<HTML><HEAD>
<META content="text/html; charset=utf-8" http-equiv=Content-Type>
<META name=GENERATOR content="MSHTML 8.00.6001.19222"></HEAD>
<BODY style="MARGIN: 4px 4px 1px; FONT: 10pt Tahoma">
<DIV>All,</DIV>
<DIV>I'd like to convert a continuous raster to binary (0, 1). Here's what I've come up with</DIV>
<DIV> </DIV>
<DIV>library(raster)</DIV>
<DIV> </DIV>
<DIV>#build the sample raster<BR>r <- raster(ncol=100, nrow=100)<BR>r[] <- round(runif(ncell(r)) * 10)<BR></DIV>
<DIV>#set up a cut point, cut it</DIV>
<DIV>ctpts <- c(0,3.5,10)<BR>rc <- cut(r,breaks=ctpts)</DIV>
<DIV> </DIV>
<DIV>#since the result from cut was a raster with values c(1,2), use subs to change to c(0,1)<BR>subdf <- data.frame(from=c(1,2), to=c(0,1))<BR>rs <- subs(rc, subdf, subsWithNA=TRUE)<BR>rs</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>My questions:</DIV>
<DIV>1. Is there a more efficient way? (I'll be doing this to many large rasters)</DIV>
<DIV>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? </DIV>
<DIV> </DIV>
<DIV>Thanks in advance, </DIV>
<DIV>Tim</DIV></BODY></HTML>