Dear list members, I am trying to extract the 5 highest values from a 
raster, pass them to a data frame with their row and column number, and 
then use this information to create a new raster in which all of these 
rows and columns take value 1. My code so far is as follows: 
I have a raster: 

### 
r1 <- raster(nrows=10, ncols=10) 
r1[]= runif(ncell(r1)) 
### 

I can take values from it, extract and sort the 5 highest values and 
output the results with their rows and columns to a data frame: 

### 
x <- getValues(r1) 
n <- 5 
x2 <-  sort(-x, partial = n) 
x2h <-  -sort(x2[1:n]) 
ix <- which(x %in% x2h) 
ro <- ix %% 10 
ro <- ifelse(ro == 0L, 10, ro) 
co <- 1 + ix %/% 10 
x3 <- x[ix] 
d <- data.frame(row = ro, col = co, x = x3) 
result <- d[rev(order(d$x)), ] 

### 
but, having done that, how can I create a new raster and assign value 1 
to these rows and columns? 
I tried: 

### 
rnew <- raster(nrows=10,ncols=10) 
rnew[(result$row),(result$col)] = 1 
### 

but this is clearly quite wrong. Can anyone help? 

Thanks 
Richard 
	[[alternative HTML version deleted]]

