Skip to contents

Divides a two-dimensional cloud of points in blocks according to a user-defined number of rows and columns. This is applied to the element master_matrix and, if not NULL, to preselected_sites.

Usage

make_blocks(master_matrix, variable_1, variable_2, n_cols, n_rows = NULL,
            block_type = "equal_area")

Arguments

master_matrix

object derived from function prepare_master_matrix.

variable_1

(character or numeric) name or position of the first variable (x-axis) to be used to create blocks.

variable_2

(character or numeric) name or position of the second variable (y-axis) to be used to create blocks (must be different from the first one).

n_cols

(numeric) number of columns of a grid used to creates blocks and split the bi-dimensional space.

n_rows

(numeric) number of rows of a grid used to creates blocks and split the bi-dimensional space. If NULL, the default, n_rows = n_cols.

block_type

(character) type of blocks to be use for dividing the bi-dimensional space. Two options are available: "equal_area" and "equal_points". Default = "equal_area".

Value

An S3 object of class master_matrix, containing the same elements found in a master_matrix object, with an additional column on the master_matrix data.frame containing block identifiers. If the element preselected_sites is not NULL in master_matrix, blocks are also assigned to this sites.

Details

For block_type, option "equal_area" generates blocks of the same size. The other option ("equal_points"), generates blocks containing the same number of points, which generally results in blocks of different sizes.

Examples

# Data
m_matrix <- read_master(system.file("extdata/m_matrix.rds",
                                    package = "biosurvey"))

# Creating blocks
m_blocks <- make_blocks(m_matrix, variable_1 = "PC1",
                        variable_2 = "PC2", n_cols = 10, n_rows = 10,
                        block_type = "equal_area")
unique(m_blocks$data_matrix$Block)
#>  [1]   5   4   2  23  24   1   6   3  25   7  26  27   8  35  28  36  37  38  29
#> [20]  34  39  47  30  48  40  41  46  49  59  60  70  72  71  58  50  62  61  51
#> [39]  73  63  84  57  85  95  52  75  42  45  31   9  32  82  94  83  81  69  96
#> [58]  74 107 106  93 105 117 118  56