rts2list.Rdrts2list converts route result matrix into a list of individual
matrices based on the supplied index which is typically part of the
matrix.
rts2list(rts, nrow = max(index), index = rts[, 3])The matrix rts is split into indiviudal matrices according to
the index. It is similar to split(rts, index) except
that the result has exactly nrow entries corresponding the the
indices 1 .. nrow and index must be contiguous. Any missing
entries (i.e., indices between 1 and nrow which are not in
index) are filled with NULL.
A list of exactly nrow elements. The entries are either
NULL (index not present) or the corresponding slice of the
matrix.
m = matrix(1:10,, 2)
rts2list(m, 3, c(1,1,1,3,3))
#> [[1]]
#> [,1] [,2]
#> [1,] 1 6
#> [2,] 2 7
#> [3,] 3 8
#>
#> [[2]]
#> NULL
#>
#> [[3]]
#> [,1] [,2]
#> [1,] 4 9
#> [2,] 5 10
#>
## route matrices have the index as 3rd column
m = cbind(m, c(1,1,1,3,3))
## let's say the input had 5 pairs
rts2list(m, 5)
#> [[1]]
#> [,1] [,2] [,3]
#> [1,] 1 6 1
#> [2,] 2 7 1
#> [3,] 3 8 1
#>
#> [[2]]
#> NULL
#>
#> [[3]]
#> [,1] [,2] [,3]
#> [1,] 4 9 3
#> [2,] 5 10 3
#>
#> [[4]]
#> NULL
#>
#> [[5]]
#> NULL
#>