Skip to contents

Replace the lower right triangle of the matrix with NAs

Usage

replace_lower_right_with_NA(matrix)

Arguments

matrix

Matrix

Value

A matrix of the same dimensions, with NAs for all the lower right entries.

Examples

triangle_w_zeros <- matrix(
  c(
    1, 3, 5, 7,
    4, 7, 8, 0,
    9, 10, 0, 0,
    3, 0, 0, 0
  ),
  nrow = 4,
  byrow = TRUE
)

rep_tri <- replace_lower_right_with_NA(triangle_w_zeros)
print(rep_tri)
#>      [,1] [,2] [,3] [,4]
#> [1,]    1    3    5    7
#> [2,]    4    7    8   NA
#> [3,]    9   10   NA   NA
#> [4,]    3   NA   NA   NA