<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>What a fabulous collection of answers!  </DIV>
<DIV> </DIV>
<DIV>For my bigger grids that can't reside in memory, I think I need to use calc in regards to Thierry's and Matt's approach, like this:</DIV>
<DIV> </DIV>
<DIV>func <- function(x){x > 3.5}  #still need to add "as</DIV>
<DIV>r <- calc(r, fun=func, filename = ...)</DIV>
<DIV> </DIV>
<DIV>So, following Rafael's note that reclass was faster than subs alone, here are timings on real data comparing reclass to calc. </DIV>
<DIV> </DIV>
<DIV>> func <- function(x){x > ctpt}</DIV>
<DIV>> system.time(rasCtc <- calc(ras, fun=func, filename=out1, format = "GTiff", datatype = "INT1U"))</DIV>
<DIV>   user  system elapsed <BR> 119.16   28.00  147.37 <BR>> system.time(rasCt <- reclass(ras, rccutpt, filename=out2, format = "GTiff", datatype = "INT1U"))<BR>   user  system elapsed <BR> 119.85   28.38  148.44 <BR></DIV>
<DIV>They are very close, and perhaps not even significantly different, but calc may be edging out reclass by a small amount.  Brilliant!</DIV>
<DIV> </DIV>
<DIV>Thanks everyone, for the help. </DIV>
<DIV>Best,</DIV>
<DIV>Tim</DIV>
<DIV><BR><BR>>>> Matthew Landis <landis@isciences.com> 6/14/2012 11:37 AM >>><BR><BR>In terms of Tim's example:<BR><BR>plot(r)<BR>r[] <- as.numeric(r[] > 3.5)<BR>plot(r)<BR><BR>works for me.  Made only a small change from Thierry's elegant example <BR>to return numeric instead of boolean.<BR><BR>M<BR><BR>On 6/14/2012 9:56 AM, ONKELINX, Thierry wrote:<BR>> How about<BR>> rs<- r>  0.35<BR>> or<BR>> rs<-(r>  0.35) * 1<BR>> untested!<BR>><BR>> Best regards,<BR>> Thierry<BR>> ir. Thierry Onkelinx<BR>> Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest<BR>> team Biometrie&  Kwaliteitszorg / team Biometrics&  Quality Assurance<BR>> Kliniekstraat 25<BR>> 1070 Anderlecht<BR>> Belgium<BR>> + 32 2 525 02 51<BR>> + 32 54 43 61 85<BR>> Thierry.Onkelinx@inbo.be<mailto:Thierry.Onkelinx@inbo.be><BR>> www.inbo.be<<A href="http://www.inbo.be/">http://www.inbo.be/</A>><BR>><BR>> To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of.<BR>> ~ Sir Ronald Aylmer Fisher<BR>><BR>> The plural of anecdote is not data.<BR>> ~ Roger Brinner<BR>><BR>> The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data.<BR>> ~ John Tukey<BR>><BR>> Van: r-sig-geo-bounces@r-project.org [mailto:r-sig-geo-bounces@r-project.org] Namens Tim Howard<BR>> Verzonden: donderdag 14 juni 2012 15:02<BR>> Aan: r-sig-geo@r-project.org<BR>> Onderwerp: [R-sig-Geo] continuous raster to binary<BR>><BR>> All,<BR>> I'd like to convert a continuous raster to binary (0, 1). Here's what I've come up with<BR>><BR>> library(raster)<BR>><BR>> #build the sample raster<BR>> r<- raster(ncol=100, nrow=100)<BR>> r[]<- round(runif(ncell(r)) * 10)<BR>> #set up a cut point, cut it<BR>> ctpts<- c(0,3.5,10)<BR>> rc<- cut(r,breaks=ctpts)<BR>><BR>> #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<BR>><BR>><BR>> My questions:<BR>> 1. Is there a more efficient way? (I'll be doing this to many large rasters)<BR>> 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?<BR>><BR>> Thanks in advance,<BR>> Tim<BR>> ~<BR></DIV></BODY></HTML>