| ClusterApply | R Documentation |
Applies a given function to each data dimension separately within each cluster.
ClusterApply(DataOrDistances,FUN,Cls,Simple=FALSE,...)
DataOrDistances |
Either a symmetric [1:n,1:n] distance matrix or: a [1:n,1:d] matrix containing |
FUN |
Function to be applied to each cluster of data and each column of data |
Cls |
[1:n] numerical vector with n numbers defining the classification as the main output of the clustering algorithm. It has k unique numbers representing the arbitrary labels of the clustering. |
Simple |
Boolean, if TRUE, simplifies output |
... |
Additional parameters to be passed on to FUN |
Applies FUN to each feature within each cluster defined by Cls. If Cls is missing, all observations are assigned to one cluster. The main output contains the result of FUN for each cluster and is named after the supplied function.
For a distance matrix, classical multidimensional scaling is used automatically to obtain coordinates. The number of dimensions is selected from the possible cmdscale output dimensions by minimum stress.
If the name of FUN cannot be extracted, the component is named ResultPerCluster.
If Simple = FALSE, a list with:
UniqueClusters |
The unique cluster labels in |
FUNPerCluster |
A [1:k,1:d] matrix with one row per cluster and one column per feature. The component name is derived from the supplied |
If Simple = TRUE, a [1:k,1:d] matrix with one row per cluster and one column per feature.
Felix Pape, Michael Thrun
##one dataset
data(Hepta)
Data=Hepta$Data
Cls=Hepta$Cls
#mean per cluster
ClusterApply(Data,mean,Cls)
#Simplified
ClusterApply(Data,mean,Cls,Simple=TRUE)
# Mean per cluster of MDS transformation
# Beware, this is not the same!
ClusterApply(as.matrix(dist(Data)),mean,Cls)
## Not run:
Iris=datasets::iris
Distances=as.matrix(Iris[,1:4])
SomeFactors=Iris$Species
V=ClusterCreateClassification(SomeFactors)
Cls=V$Cls
V$ClusterNames
ClusterApply(Distances,mean,Cls)
## End(Not run)
#special case of identity
## Not run:
suppressPackageStartupMessages(library('prabclus',quietly = TRUE))
data(tetragonula)
#Generated Specific Distance Matrix
ta <- alleleconvert(strmatrix=as.matrix(tetragonula[1:236,]))
tai <- alleleinit(allelematrix=ta,distance="none")
Distance=alleledist((unbuild.charmatrix(tai$charmatrix,236,13)),236,13)
MDStrans=ClusterApply(Distance,identity)$identityPerCluster
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.