R/Transition-extract-replace.R
Transition-extract-replace.Rd
Methods for functions [
and [<-
for object of
the class TransitionLayer.
transitionMatrix(x) <- value
an object of class Transition*
the value to assign
Methods for functions [[
and [[<-
for object of
the class TransitionStack.
Also see adjacencyFromTransition
.
#Create a new raster and set all its values to unity.
r <- raster(nrows=18, ncols=36)
r <- setValues(r,rep(1,ncell(r)))
#Create TransitionLayer objects
tr1 <- transition(r,mean,4)
#> The extent and CRS indicate this raster is a global lat/lon raster. This means that transitions going off of the East or West edges will 'wrap' to the opposite edge.
#> Global lat/lon rasters are not supported under new optimizations for 4 and 8 directions with custom transition functions. Falling back to old method.
tr2 <- tr1
#Extracting and replacing
tr1[cbind(1:9,1:9)] <- tr2[cbind(1:9,1:9)]
tr1[1:9,1:9] <- tr2[1:9,1:9]
tr1[1:5,1:5]
#> 5 x 5 sparse Matrix of class "dsCMatrix"
#>
#> [1,] . 1 . . .
#> [2,] 1 . 1 . .
#> [3,] . 1 . 1 .
#> [4,] . . 1 . 1
#> [5,] . . . 1 .