R/flattenCorrMatrix.R

Defines functions flattenCorrMatrix

Documented in flattenCorrMatrix

#' Creates a corelations matrix and flatten it
#'
#' `flattenCorrMatrix` Takes a DF, calculates the correlations between
#' the diffrent variables. Next it flatten it into a data.frame.
#' @param DF The DF you want the flatten correlation matrix.
#' @return DF of flatten martrix.
#' @note You need to have Hmisc pkg
#' @examples
#' flattenCorrMatrix(DF)


flattenCorrMatrix <- function(DF) {
    #Creating the correaltion matrix
    DF <- DF %>%
    as.matrix() %>%
    rcorr()

    #Flattening the correlation matrix
    ut <- upper.tri(DF$r)
    flat <- data.frame(
      row = rownames(DF$r)[row(DF$r)[ut]],
      column = rownames(DF$r)[col(DF$r)[ut]],
      cor = (DF$r)[ut],
      p = DF$P[ut],
      n = DF$n[ut])
    return(flat)
}
AmirDJV/UsefulFunctions documentation built on Nov. 18, 2017, 5:10 a.m.