\name{Clusters}
\alias{Clusters}
\title{
  The K-means cluster analysis.
}
\description{
  This function computes clusters and their time series of occurrences  
  the K-mean clustering method on a matrix of input var (time, space). 
  It requires NbClust package. 
}
\usage{
  Clusters(var, weights, nclusters=NULL, listindex=NULL')
}
\arguments{
  \item{var}{
    A matrix (time, space); the 2nd spatial dimension can correspond either  
    to area-averages over a series of domains or the grid points for any
    grid (x,y), (x,y,z), (y,z), .. organised in an array for each time step.
  }
  \item{weights}{ 
    A vector of weights corresponding to the areas covering each domain/region
    or grid-cell of var; the length of weights vector should equal to the 2nd
    spatial dimension of var.
  }
  \item{nclusters}{
    K number of clusters to be computed, or K initial cluster centers 
    (default is NULL and then function  will determine the optimal number 
    of clusters and their centers, but it can be a CPU intense process).
  }
  \item{listindex}{
    List of validity indices (from NbClust package plus 'first') used to determine optimal 
    K if it is not specified via positive integer bigger than 1 or initial/seed cluster 
    centers in nclusters (NULL is deafult which leads to application of: 'kl', 'ch', 
    'duda', 'ratkowsky', 'ball', 'ptbiserial', 'gap', 'mcclain', 'tau', and 'sdindex'). 
  }
}
\value{
  \item{$clusters}{ 
    A vector (time series) of integers indicating the occurrence of a cluster, i.e., when
    certain data member in time is allocated to a specific cluster (e.g., 2 1 3 1 1 1 ..).
  }
  \item{$centers}{
    A matrix of cluster centres or centroids (e.g. [1:K, 1:spatial degrees of freedom]).
  }
  \item{$totss}{
    The total sum of squares. 
  }
  \item{$withinss}{
    A vector of within-cluster sum of squares, one component per cluster. 
  }
  \item{$tot.withinss}{
    Total within-cluster sum of squares, i.e., sum(withinss). 
  }
  \item{$betweenss}{
    The between-cluster sum of squares, i.e. totss-tot.withinss. 
  }
  \item{$size}{
    The number of points in each cluster. 
  }
}
\examples{

}
\author{
  History:
  1.0  #  2014-10  (N.S. Fuckar, neven.fuckar@bsc.es)  #  Original code
}
\keyword{datagen}
