-
-
Notifications
You must be signed in to change notification settings - Fork 55
/
utils.R
28 lines (26 loc) · 603 Bytes
/
utils.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#' 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
}
}