R/eigen2.R

Defines functions eigen2

Documented in eigen2

#' Calculate eigendecomposition and return ordered eigenvalues and eigenvectors
#'
#' @param spd a semi-positive definite matrix
#' @param decreasing argument passed to order()
#' @export
#' @examples
#' readr::read_tsv(system.file("extdata",
#' "mouse100.cXX.txt",
#' package = "gemma2"),
#' col_names = FALSE)[, 1:100] -> kinship
#' e_out <- eigen2(as.matrix(kinship))
#' @return a list with 2 components, the eigenvalues and the eigenvectors
eigen2 <- function(spd, decreasing = FALSE){
  eigen(spd) -> foo
  bar <- foo
  bar$values <- foo$values[order(foo$values, decreasing = decreasing)]
  bar$vectors <- foo$vectors[, order(foo$values, decreasing = decreasing)]
  return(bar)
}

Try the gemma2 package in your browser

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

gemma2 documentation built on Oct. 24, 2020, 5:06 p.m.