R/getPN.R

Defines functions .getPN

#'
#' Get the Positive or Negative Values in a Matrix
#'
#' @export
#' @noRd
#'

.getPN <- function(M) {
  # Get either the (+)-ive or (-)-ive values in a matrix
  # depending upon which is most extreme in absolute terms,
  # and return them as a vector of positive values

  # Be sure to weed out NA's

  neg <- M[M < 0] # these are vectors
  neg <- neg[!is.na(neg)]
  pos <- M[M > 0]
  pos <- pos[!is.na(pos)]
  if (length(pos) == 0) {
    return(neg)
  } # no + values
  if (length(neg) == 0) {
    return(pos)
  } # no - values
  exP <- .findExtreme(pos)
  exN <- .findExtreme(neg)
  if (exP >= exN) {
    return(pos)
  }
  if (exN > exP) {
    return(abs(neg))
  }
}

Try the ChemoSpec2D package in your browser

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

ChemoSpec2D documentation built on Oct. 11, 2021, 9:06 a.m.