I suppose it worked for me because I already added the %in% function. In
which case the 'Which in "Which( x %in% c(2,4,6))" is entirely redundant;
but you need the %in% function. Either way, calc should work. Robert

On Sun, Oct 30, 2011 at 9:00 PM, steven mosher <moshersteven@gmail.com>wrote:

> hmm, as you say looks like an issue with match
>
> newRaster <- Which(randomRaster ==2 | randomRaster ==4 | randomRaster ==6)
>
>
> works.
>
>
> On Sun, Oct 30, 2011 at 8:45 PM, pgalpern <pgalpern@gmail.com> wrote:
>
>>  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.
>>
>> 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.
>>
>> randomRaster <- raster(ncol=25, nrow=25)
>> randomRaster[] <- floor(abs(runif(ncell(randomRaster))*10))
>> newRaster <- Which(randomRaster %in% c(2,4,6))
>>
>> So am guessing that %in% and match still need to be implemented.
>>
>> Best,
>> Paul
>>
>>
>> On 30/10/2011 10:29 PM, Robert J. Hijmans wrote:
>>
>> Yes, shorter still:
>>
>>  newRaster <- Which(randomRaster %in% c(2, 4, 6))
>>
>>
>>  On Sun, Oct 30, 2011 at 7:19 PM, steven mosher <moshersteven@gmail.com>wrote:
>>
>>> ?Which
>>>
>>> On Sun, Oct 30, 2011 at 6:55 PM, pgalpern <pgalpern@gmail.com> wrote:
>>>
>>> > Hello!
>>> >
>>> > Wondering if there is an efficient raster package approved way of
>>> > comparing values to a lookup list (as one would using the %in%
>>> operator).
>>> >
>>> > ## Make a random raster with cell values 0 through 9 for illustration
>>> > library(raster)
>>> > randomRaster <- raster(ncol=25, nrow=25)
>>>  > randomRaster[] <- floor(abs(runif(ncell(**clumpyRaster))*10))
>>> >
>>> > ## Now make a new binary raster in which the cells with values 2, 4 or
>>> 6
>>> > are set
>>> > ## This fails probably because %in% has not been implemented!
>>> > newRaster <- randomRaster %in% c(2, 4, 6)
>>> >
>>> > ## My clunky alternative
>>> > newRaster <- calc(randomRaster, function(x) sapply(x, function(y) if (y
>>> > %in% c(2, 4, 6)) return(1) else return(0)))
>>> >
>>> > This works, but is messy.  Am I missing a better way?
>>> >
>>> > By the way--raster package is a revolution (fine work is much
>>> appreciated).
>>> >
>>> > Thanks,
>>> > Paul
>>> >
>>> > --
>>> > Paul Galpern, PhD Candidate
>>> > Natural Resources Institute
>>> > 70 Dysart Road
>>> > University of Manitoba
>>> > Winnipeg, Manitoba, Canada R3T 2M6
>>> > http://borealscape.ca
>>> >
>>>  > ______________________________**_________________
>>> > R-sig-Geo mailing list
>>> > R-sig-Geo@r-project.org
>>> > https://stat.ethz.ch/mailman/**listinfo/r-sig-geo<
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo>
>>> >
>>>
>>>        [[alternative HTML version deleted]]
>>>
>>> _______________________________________________
>>> R-sig-Geo mailing list
>>> R-sig-Geo@r-project.org
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>
>>
>

	[[alternative HTML version deleted]]

