marxan_connectivity_data_to_matrix {prioritizr} | R Documentation |
Convert Marxan connectivity data to matrix format
Description
Convert a data.frame
object containing Marxan connectivity data
to matrix format. This function is designed specifically for
connectivity data (not boundary data).
It ensures that the output matrix correctly specifies
symmetric or asymmetric connectivity relationships between planning units.
Usage
marxan_connectivity_data_to_matrix(x, data, symmetric = TRUE)
Arguments
x |
|
data |
|
symmetric |
|
Value
A dgCMatrix
sparse matrix object.
Examples
## Not run:
# create marxan connectivity data with four planning units and one zone,
# and symmetric connectivity values
bldf1 <- expand.grid(id1 = seq_len(4), id2 = seq_len(4))
bldf1$boundary <- 1
bldf1$boundary[bldf1$id1 == bldf1$id2] <- 0.5
# print data
print(bldf1)
# convert to matrix
m1 <- marxan_connectivity_data_to_matrix(NULL, bldf1)
# print matrix
print(m1)
# visualize matrix
image(m1)
# create marxan connectivity data with four planning units and one zone,
# and asymmetric connectivity values
bldf2 <- expand.grid(id1 = seq_len(4), id2 = seq_len(4))
bldf2$boundary <- runif(nrow(bldf2))
bldf2$boundary[bldf1$id1 == bldf1$id2] <- 0.5
# print data
print(bldf2)
# convert to matrix
m2 <- marxan_connectivity_data_to_matrix(NULL, bldf2, symmetric = FALSE)
# print matrix
print(m2)
# visualize matrix
image(m2)
# create marxan connectivity with three planning units and two zones,
# and symmetric connectivity values
bldf3 <- expand.grid(
id1 = seq_len(3), id2 = seq_len(3),
zone1 = c("z1", "z2"),
zone2 = c("z1", "z2")
)
bldf3$boundary <- 1
bldf3$boundary[bldf2$id1 == bldf2$id2 & bldf2$zone1 == bldf2$zone2] <- 0.5
bldf3$boundary[bldf2$id1 == bldf2$id2 & bldf2$zone1 != bldf2$zone2] <- 0
# print data
print(bldf3)
# convert to array
m3 <- marxan_connectivity_data_to_matrix(NULL, bldf3)
# print array
print(m3)
## End(Not run)