<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    Thanks for the suggestions.  The calc() approach works fine, and I
    can think of other even more clunky ways, but just thinking about
    efficiency, here.  <br>
    <br>
    I was pleased to find Which(), which I had overlooked.  But the
    following still throws an error on raster 1.9-33 under 2.13.2.<br>
    <br>
    randomRaster <- raster(ncol=25, nrow=25)<br>
    randomRaster[] <- floor(abs(runif(ncell(randomRaster))*10))<br>
    newRaster <- Which(randomRaster %in% c(2,4,6))<br>
    <br>
    So am guessing that %in% and match still need to be implemented.<br>
    <br>
    Best, <br>
    Paul<br>
    <br>
    On 30/10/2011 10:29 PM, Robert J. Hijmans wrote:
    <blockquote
cite="mid:CANtt_hzW8o2-pRAZSgcMhcuoWODs2bK5GTbXof9=3h_9byr6ZA@mail.gmail.com"
      type="cite">
      <div><span class="Apple-style-span" style="font-family: arial,
          sans-serif; font-size: 13px; background-color: rgb(255, 255,
          255); ">Yes, shorter still:</span></div>
      <div><span class="Apple-style-span" style="font-family: arial,
          sans-serif; font-size: 13px; background-color: rgb(255, 255,
          255); "><br>
        </span></div>
      <span class="Apple-style-span" style="font-family: arial,
        sans-serif; font-size: 13px; background-color: rgb(255, 255,
        255); ">newRaster <- Which(randomRaster %in% c(2, 4, 6))</span><br>
      <br>
      <br>
      <div class="gmail_quote">
        On Sun, Oct 30, 2011 at 7:19 PM, steven mosher <span dir="ltr"><<a
            moz-do-not-send="true" href="mailto:moshersteven@gmail.com">moshersteven@gmail.com</a>></span>
        wrote:<br>
        <blockquote class="gmail_quote" style="margin:0 0 0
          .8ex;border-left:1px #ccc solid;padding-left:1ex;">
          ?Which<br>
          <div class="im"><br>
            On Sun, Oct 30, 2011 at 6:55 PM, pgalpern <<a
              moz-do-not-send="true" href="mailto:pgalpern@gmail.com">pgalpern@gmail.com</a>>
            wrote:<br>
            <br>
            > Hello!<br>
            ><br>
            > Wondering if there is an efficient raster package
            approved way of<br>
            > comparing values to a lookup list (as one would using
            the %in% operator).<br>
            ><br>
            > ## Make a random raster with cell values 0 through 9
            for illustration<br>
            > library(raster)<br>
            > randomRaster <- raster(ncol=25, nrow=25)<br>
          </div>
          > randomRaster[] <-
          floor(abs(runif(ncell(**clumpyRaster))*10))<br>
          <div class="im">><br>
            > ## Now make a new binary raster in which the cells with
            values 2, 4 or 6<br>
            > are set<br>
            > ## This fails probably because %in% has not been
            implemented!<br>
            > newRaster <- randomRaster %in% c(2, 4, 6)<br>
            ><br>
            > ## My clunky alternative<br>
            > newRaster <- calc(randomRaster, function(x)
            sapply(x, function(y) if (y<br>
            > %in% c(2, 4, 6)) return(1) else return(0)))<br>
            ><br>
            > This works, but is messy.  Am I missing a better way?<br>
            ><br>
            > By the way--raster package is a revolution (fine work
            is much appreciated).<br>
            ><br>
            > Thanks,<br>
            > Paul<br>
            ><br>
            > --<br>
            > Paul Galpern, PhD Candidate<br>
            > Natural Resources Institute<br>
            > 70 Dysart Road<br>
            > University of Manitoba<br>
            > Winnipeg, Manitoba, Canada R3T 2M6<br>
            > <a moz-do-not-send="true" href="http://borealscape.ca"
              target="_blank">http://borealscape.ca</a><br>
            ><br>
          </div>
          > ______________________________**_________________<br>
          > R-sig-Geo mailing list<br>
          > <a moz-do-not-send="true"
            href="mailto:R-sig-Geo@r-project.org">R-sig-Geo@r-project.org</a><br>
          > <a moz-do-not-send="true"
            href="https://stat.ethz.ch/mailman/**listinfo/r-sig-geo"
            target="_blank">https://stat.ethz.ch/mailman/**listinfo/r-sig-geo</a><<a
            moz-do-not-send="true"
            href="https://stat.ethz.ch/mailman/listinfo/r-sig-geo"
            target="_blank">https://stat.ethz.ch/mailman/listinfo/r-sig-geo</a>><br>
          ><br>
          <br>
                 [[alternative HTML version deleted]]<br>
          <div>
            <div class="h5"><br>
              _______________________________________________<br>
              R-sig-Geo mailing list<br>
              <a moz-do-not-send="true"
                href="mailto:R-sig-Geo@r-project.org">R-sig-Geo@r-project.org</a><br>
              <a moz-do-not-send="true"
                href="https://stat.ethz.ch/mailman/listinfo/r-sig-geo"
                target="_blank">https://stat.ethz.ch/mailman/listinfo/r-sig-geo</a><br>
            </div>
          </div>
        </blockquote>
      </div>
    </blockquote>
  </body>
</html>