Skip to contents

This helper function can be useful for visualizing heatmap patterns of a numeric matrix with values that are extremely similar.

Usage

pd_diagonal(data, replace = "median")

Arguments

data

A square, numeric dataframe, matrix or tibble.

replace

A string or numeric value to replace the matrix diagonal. Options include "min", "max", "mean", "median", "mode" and "geometric". If replace is numeric instead of string, the new diagonal will be the numeric input value.

Value

A square, numeric matrix with new diagonal.

Details

Summary replacements retain missing values except for "geometric", which uses only positive, non-missing entries.

References

Muchmore, B., Muchmore P. and Alarcón-Riquelme ME. (2018). Optimal Distance Matrix Construction with PreciseDist and PreciseGraph.

Author

Brian Muchmore

Examples

test_matrix <- replicate(10, rnorm(10))

test_result_1 <- test_matrix %>%
  pd_diagonal()

test_result_2 <- test_matrix %>%
  pd_diagonal(replace = "geometric")

test_result_3 <- test_matrix %>%
  pd_diagonal(replace = 0)