count_subareas: Count the Number of Ones in Subareas of a Matrix

View source: R/count_subareas.R

count_subareasR Documentation

Count the Number of Ones in Subareas of a Matrix

Description

This function takes a binary matrix (0s and 1s) and divides it into rectangular subareas, counting the number of ones in each. Subareas are defined by the number of rows and columns specified by the user. If the matrix dimensions are not perfectly divisible by the subarea size, edge subareas may be smaller.

Usage

count_subareas(matrix_data, sub_rows, sub_cols)

Arguments

matrix_data

A matrix of 0s and 1s to analyze.

sub_rows

Number of rows in each subarea.

sub_cols

Number of columns in each subarea.

Value

A matrix where each cell corresponds to a subarea and contains the count of ones.

See Also

Other Spatial analysis: AFSD(), BPL(), count_subareas_random(), fit_gradients(), join_count(), oruns_test(), oruns_test_boustrophedon(), oruns_test_byrowcol(), plot_AFSD()

Examples

set.seed(123)
mat <- matrix(sample(c(0, 1), 12 * 16, replace = TRUE), nrow = 16, ncol = 12)
count_matrix <- count_subareas(mat, sub_rows = 3, sub_cols = 3)
print(count_matrix)


r4pde documentation built on July 2, 2025, 5:09 p.m.