Round matrix by blocks
round_by_blocks.Rd
Applies round_matrix()
to equally-sized blocks that partition the
matrix either vertically or horizontally.
Arguments
- Y
Matrix.
- layout
The blocks are distributed: 1 horizontally, 2 vertically.
- L
Number of lines that a block encompasses.
- digits
Number of decimal places to be rounded to.
- MARGIN_BLOCK
For each block
0 Preserves the rounded colSums and rowSums.
1 Preserves the rounded rowSums independently of each other.
2 Preserves the rounded colSums independently of each other.
Examples
set.seed(10)
Y <- (rnorm(32)*10) |> matrix(ncol = 2) |> round(3)
X <- round_by_blocks(Y, 2, 4)
U <- Y[5:8,] |> round_matrix()
X[5:8,] - U
#> [,1] [,2]
#> [1,] 0 0
#> [2,] 0 0
#> [3,] 0 0
#> [4,] 0 0