Revision 923d0cc1f43c36debbea1f1fb06e4de448065380 authored by Gilles Raiche on 31 August 2019, 09:11:55 UTC, committed by cran-robot on 31 August 2019, 09:11:55 UTC
1 parent 592b098
Raw File
eigenFrom.r
eigenFrom <-
function(x) {
 classType <- class(x)
 
 res <- switch (classType,
  data.frame  = "data",
  matrix      = "correlation",
  numeric     = "eigenvalues",
  stop("Not a data.frame, a matrix, or a numeric vector")
  )
  
 switch (res,
  data        = if (dim(x)[2] <= 2) stop("At least 3 variables must be supplied"),
  correlation = if (dim(x)[2] <= 2) stop("At least 3 variables must be supplied"),
  eigenvalues = if (length(x) <= 2) stop("A vector of 3 eigenvalues or more must be supplied")
  )
  
 if (res == "correlation") if (any(x[lower.tri(x)] != t(x)[lower.tri(t(x))])) {
  stop("A correlation/covariance matrix must be symetric, empirical data must
        come from a data.frame, or eigenvalues must directly come from a vector.
        Verify the documentation about the eigenFrom function.")
  }
  
 invisible(res)
 }
  



  
back to top