R/get_cov.r

Defines functions get_cov

Documented in get_cov

#' Obtain the covariance matrix
#'
#' If the input data is a square matrix, it is converted into a matrix,
#' otherwise the covariance matrix is obtained.
#' The covariance matrix uses the cov function of base,
#' and the option for processing missing values is 'pairwise.complete.obs'.
#'
#' @param data A dataframe or a matrix
#' @return The covariance matrix
get_cov <- function(data) {
    if (nrow(data) == ncol(data)) {
        matrix <- as.matrix(data)
    } else {
        matrix <- stats::cov(data, use = "pairwise.complete.obs")
    }
    return(matrix)
}
eunscho/unirel documentation built on Dec. 20, 2021, 6:44 a.m.