#Create a new raster and set all its values to unity.
r <- raster(nrows=18, ncols=36)
r <- setValues(r, runif(ncell(r)))
#Create a Transition object from the raster
tr <- transition(r, transitionFunction=mean, directions=4)
tr #the sparse matrix is of class dsCMatrix (symmetric)
#Create an asymmetric transition matrix
#first, an arbitrary non-commutative function
f <- function(x) max(x) - x[1] + x[2]
tr2 <- transition(r, f, 4, symm=FALSE)
tr2 #the sparse matrix is of class dgCMatrix (=asymmetric)
Run the code above in your browser using DataLab