Greetings,

I have a vector of values and I want to select cells in a raster that have
these values, change these cells so they have a value of 1 and the rest of
the raster will have a NA value.

library(raster)

#my example raster
r <- raster(ncol=3, nrow=3)
r[] <- 1:ncell(r)
#a vector of cells I want to select
vals<-c(2,4,6)

#I want to select cells with the values 2,4,6 a silly way to do it:
r1<-r==2
r2<-r==4
r3<-r==6
#make the final desired raster
r4<-r1+r2+r3
plot(r4)

#I have played around with a lot of differnt things but I think I want to
use the funcion sub
######this does not work######
df = data.frame(id=c(2,4,6), v=c(1,1,1))
x = subs(r, df)



Is there a better way to do this? There must be a better way. What have I
missed? I need to be able to select raster cells from a vector.

Thank you for your time and help,
Daisy


-- 
Daisy Englert Duursma
Department of Biological Sciences
Room E8C156
Macquarie University, North Ryde, NSW 2109
Australia

Tel +61 2 9850 9256

	[[alternative HTML version deleted]]

