F matrices utility function.

replaceBand(a, b, k)

Arguments

a

The matrix to be replaced

b

The matrix with the replacement values

k

The extend of the replacement: 0 (diagonal only), 1 (diagonal and first extra diagonal), in general an entry is replaced if abs(row(a) - col(a)) <= k

Value

A matrix (same size as a)

Author

Bertrand Frederic, Myriam Maumy-Bertrand.

Examples


a=matrix(1:9,3,3)
b=matrix(0,3,3)
replaceBand(a,b,0)
#>      [,1] [,2] [,3]
#> [1,]    0    4    7
#> [2,]    2    0    8
#> [3,]    3    6    0
replaceBand(a,b,1)
#>      [,1] [,2] [,3]
#> [1,]    0    0    7
#> [2,]    0    0    0
#> [3,]    3    0    0
replaceBand(a,b,2)
#>      [,1] [,2] [,3]
#> [1,]    0    0    0
#> [2,]    0    0    0
#> [3,]    0    0    0