擅长:python、mysql、java
<p>希望这有帮助。在</p>
<pre><code># create fake raster
fakeRaster <- raster(matrix(ncol = 10, nrow = 10))
# place values 1 to number of cells; so the right most value
# of each row should be the highest
values(fakeRaster) <- 1:ncell(fakeRaster)
# introduce higher values somewhere; test points
values(fakeRaster)[75] <- 300
values(fakeRaster)[1] <- 300
values(fakeRaster)[100] <- 300
values(fakeRaster)[81] <- 300
values(fakeRaster)[45] <- 300
# extract values as matrix
dataRaster <- values(fakeRaster, format = "matrix")
# get every row; evalute if equal to max, if yes give 1, if no give 0
# then transpose the output
dataRaster <- t(apply(dataRaster, 1, FUN = function(x) ifelse(x == max(x, na.rm = T), 1, 0) ))
# reassign value to raster
values(fakeRaster) <- dataRaster
</code></pre>
<p>顺便说一句,当你这样做的时候:</p>
^{pr2}$
<p>最后得到一个向量(我想),这给了你问题。您也可以尝试我在上面示例中使用的值(光栅,format=“matrix”)。在</p>