Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

marxan_boundary_data_to_matrix

Convert Marxan boundary data to a matrix format


Description

Convert a data.frame object that follows the Marxan format to a matrix format. This function is useful for converting data.frame objects to matrix or array objects that are used by the various penalties and constraints functions. If the boundary data contains data for a single zone, then a matrix object is returned. Otherwise if the boundary data contains data for multiple zones, then an array is returned.

Usage

marxan_boundary_data_to_matrix(x, data)

Arguments

x

problem() (i.e. ConservationProblem) object that contains planning unit and zone data to ensure that the argument to data is converted correctly. This argument can be set to NULL if checks are not required (not recommended).

data

data.frame object with the columns "id1", "id2", and "boundary". The columns "zone1" and "zone2" can also be provided to indicate zone data.

Value

array or dgCMatrix sparse matrix object.

Examples

# create marxan boundary with four planning units and one zone
bldf1 <- expand.grid(id1 = seq_len(4), id2 = seq_len(4))
bldf1$boundary <- 1
bldf1$boundary[bldf1$id1 == bldf1$id2] <- 0.5

# convert to matrix
m1 <- marxan_boundary_data_to_matrix(NULL, bldf1)

# visualize matrix
## Not run: 
image(m1)

## End(Not run)
# create marxan boundary with three planning units and two zones
bldf2 <- expand.grid(id1 = seq_len(3), id2 = seq_len(3),
                     zone1 = c("z1", "z2"),
                     zone2 = c("z1", "z2"))
bldf2$boundary <- 1
bldf2$boundary[bldf2$id1 == bldf2$id2 & bldf2$zone1 == bldf2$zone2] <- 0.5
bldf2$boundary[bldf2$id1 == bldf2$id2 & bldf2$zone1 != bldf2$zone2] <- 0

# convert to array
m2 <- marxan_boundary_data_to_matrix(NULL, bldf2)

# print array
print(m2)

prioritizr

Systematic Conservation Prioritization in R

v7.0.1
GPL-3
Authors
Jeffrey O Hanson [aut] (<https://orcid.org/0000-0002-4716-6134>), Richard Schuster [aut, cre] (<https://orcid.org/0000-0003-3191-7869>), Nina Morrell [aut], Matthew Strimas-Mackey [aut] (<https://orcid.org/0000-0001-8929-7776>), Matthew E Watts [aut], Peter Arcese [aut] (<https://orcid.org/0000-0002-8097-482X>), Joseph Bennett [aut] (<https://orcid.org/0000-0002-3901-9513>), Hugh P Possingham [aut] (<https://orcid.org/0000-0001-7755-996X>)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.