How about
rs <- r > 0.35
or
rs <-(r > 0.35) * 1
untested!

Best regards,
Thierry
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest
team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
Kliniekstraat 25
1070 Anderlecht
Belgium
+ 32 2 525 02 51
+ 32 54 43 61 85
Thierry.Onkelinx@inbo.be<mailto:Thierry.Onkelinx@inbo.be>
www.inbo.be<http://www.inbo.be/>

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.
~ Sir Ronald Aylmer Fisher

The plural of anecdote is not data.
~ Roger Brinner

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.
~ John Tukey

Van: r-sig-geo-bounces@r-project.org [mailto:r-sig-geo-bounces@r-project.org] Namens Tim Howard
Verzonden: donderdag 14 juni 2012 15:02
Aan: r-sig-geo@r-project.org
Onderwerp: [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
* * * * * * * * * * * * * D I S C L A I M E R * * * * * * * * * * * * *
Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is door een geldig ondertekend document.
The views expressed in this message and any annex are purely those of the writer and may not be regarded as stating an official position of INBO, as long as the message is not confirmed by a duly signed document.

	[[alternative HTML version deleted]]

