R/ClusterCreateClassification.R

Defines functions ClusterCreateClassification

Documented in ClusterCreateClassification

ClusterCreateClassification=function(Objects,Decreasing){
  #
  # INPUT
  # Objects          listed objects, for example factor
  #
  # OUTPUT
  # Cls[1:n]         Clustering of data
  # ClusterNames     Object of adpclust algorithm
  # Decreasing        if not missing, objects are sorted
  # Author: MT
  if(is.list(Objects)) Objects=unlist(Objects)
  y=as.character(Objects)

  n=length(y)
  u=unique(y,fromLast = FALSE)
  if(!missing(Decreasing)){
    u=sort(u,decreasing = Decreasing,na.last=TRUE)
  }
  names(u)=1:length(u)
  Cls=rep(NaN,n)
  u_num=as.numeric(u)
  nans=sum(!is.finite(u_num))
  if(nans>0){
    for(i in 1:length(u)){
      Cls[y==u[i]]=i
    }
  }else{#special case: all levels are numeric
    for(i in 1:length(u)){
      Cls[y==u[i]]=u_num[i]
    }
  }
 

  return(list(Cls=Cls,ClusterNames=u))
}

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.