Learn R Programming

flexclust (version 0.8-0)

conversion: Convert S3 Partition Objects to KCCA

Description

These functions can be used to convert the results from cluster functions like kmeans or pam to objects of class "kcca".

Usage

as.kcca(object, ...)

## S3 method for class 'kmeans': as.kcca(object, data, ...) ## S3 method for class 'partition': as.kcca(object, data=NULL, ...)

Arguments

object
fitted object.
data
data which were used to obtain the clustering. For "partition" objects created by functions from package cluster this is optional, if object contains the data.
...
currently not used.

Examples

Run this code
data(Nclus)

cl1 = kmeans(Nclus, 4)
cl1
cl1a = as.kcca(cl1, Nclus)
cl1a

<testonly>stopifnot(all.equal(cl1$cluster, cluster(cl1a)))</testonly>

library("cluster")
cl2 = pam(Nclus, 4)
cl2
cl2a = as.kcca(cl2)
cl2a
## the same
cl2b = as.kcca(cl2, Nclus)
cl2b

<testonly>stopifnot(all.equal(cluster(cl2a), cluster(cl2b)))
stopifnot(all.equal(parameters(cl2a), parameters(cl2b)))</testonly>

Run the code above in your browser using DataLab