R/ClusterNormalize.R

Defines functions ClusterNormalize

Documented in ClusterNormalize

ClusterNormalize <- function(Cls) {
  # Values in Cls are consistently recoded to positive consecutive integers
  
  uniqueLabels <- sort(na.last = T, unique(Cls))
  numberOfLabels <- length(uniqueLabels)
  unique2Cls <- NULL #  initializing the vector
  
  for (i in 1:length(Cls)) {
    # calculating the indexes of elements of Cls in uniqueLabels
    unique2Cls <- c(unique2Cls, which(uniqueLabels == Cls[i]))
  }
  
  if (numberOfLabels > 0) {
    normalizedLabels <- c(1:numberOfLabels)
    normalizedCls <- normalizedLabels[unique2Cls]
  }
  else {
    normalizedLabels <- Cls
  }
  
  return(normalizedCls)
}

Try the FCPS package in your browser

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

FCPS documentation built on Oct. 19, 2023, 5:06 p.m.