R/utils.R

Defines functions isSquare is.cor

Documented in is.cor isSquare

#' Check if matrix ressembles a correlation matrix
#'
#' @param x A matrix.
#' @return `TRUE` of the matrix is a correlation matrix or `FALSE` otherwise.
#' @export
is.cor <- function(x) {
  square <- isSquare(x)
  symetric <- isSymmetric(x)
  ismatrix <- is.matrix(x)
  diag_one <- all(diag(x) == 1)
  maxi <- max(x) == 1
  all(c(square, symetric, ismatrix, diag_one, maxi))
}


#' Check if Square Matrix
#'
#' @param m A matrix.
#'
#' @return `TRUE` of the matrix is square or `FALSE` otherwise.
#' @export
isSquare <- function(m) {
  if (dim(m)[1] != dim(m)[2]) {
    FALSE
  } else {
    TRUE
  }
}

Try the correlation package in your browser

Any scripts or data that you put into this service are public.

correlation documentation built on April 6, 2023, 5:18 p.m.