Skip to contents

Given a matrix and the size of a block, returns a new matrix containing the min value for each block.

Usage

blockmin(mat, block)

Arguments

mat

numeric matrix

block

integer vector of length 2, containing the size of the block (rows, columns). If only one integer is passed, the block is square

Value

A new reduced matrix with min value of each block

Examples

mat <- matrix(1:64, nrow = 8, byrow = TRUE)
mat
#>      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
#> [1,]    1    2    3    4    5    6    7    8
#> [2,]    9   10   11   12   13   14   15   16
#> [3,]   17   18   19   20   21   22   23   24
#> [4,]   25   26   27   28   29   30   31   32
#> [5,]   33   34   35   36   37   38   39   40
#> [6,]   41   42   43   44   45   46   47   48
#> [7,]   49   50   51   52   53   54   55   56
#> [8,]   57   58   59   60   61   62   63   64

blockmin(mat, 2) # or blockmin(mat, c(2, 2))
#>      [,1] [,2] [,3] [,4]
#> [1,]    1    3    5    7
#> [2,]   17   19   21   23
#> [3,]   33   35   37   39
#> [4,]   49   51   53   55