[R-sig-Geo] Focal function in R

anusheema anusheema at gmail.com
Sun May 18 20:56:14 CEST 2014


Hi!

I want to run focal values for neighbourhood of focal cells using a matrix,
with a function preferably. My data has 0, 1, and 2 as values, and I want to
add values of "1" only, if I am using the focal function.

It's probably a very simple question, and I have tried many combinations,
but still not getting the desired results.

Please help!

Here's one of the codes that I was attempting:

# to generate the function
   my.function <- function (x) {
      ux <- unique(x)
      ux [if (x==1) ux <- focal(in_image, w=matrix(1/9, ncol=3, nrow=3)),
fun=sum]
      }

# to run the focal window for the desired function
    r_new <- focal(in_image, w=matrix(1/9, ncol=3, nrow=3), fun=my.function)



--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Focal-function-in-R-tp7586466.html
Sent from the R-sig-geo mailing list archive at Nabble.com.



More information about the R-sig-Geo mailing list