R/hs_PCA.R

Defines functions hs_PCA

Documented in hs_PCA

#' Run PCA on a hyperspec object
#'
#' @param hs.x hyperSpec object
#' @param ... Parameters to pass on to prcomp().
#' @importFrom stats prcomp
#' @examples
#' ## Short example
#'
#' # Load hyperSpec object
#' data("hs_example")
#'
#' # Convert to MassSpectrum object
#' hs.x.proc <- hs_preprocess(hs_example)
#'
#' df.PCA <- hs_PCA(hs.x.proc)
#' @export


hs_PCA <- function(hs.x, ...) {
  if (is.null(rownames(hs.x@data$spc)))
    spectra_ids <-
      hs.x@data$filename
  else
    spectra_ids <- rownames(hs.x@data$spc)
  hs.PCA <- prcomp(x = hs.x@data$spc, ...)
  hs.PCA.results <- data.frame(Spectrum_ID = spectra_ids,
    hs.PCA$x)
  return(hs.PCA.results)
}
CMET-UGent/MicroRaman documentation built on July 25, 2020, 6:20 p.m.