# ClusterApply: Applies a function over grouped data In FCPS: Fundamental Clustering Problems Suite

## Description

Applies a given function to each dimension `d` of data separately for each cluster

## Usage

 `1` ```ClusterApply(DataOrDistances,FUN,Cls,...) ```

## Arguments

 `DataOrDistances` [1:n,1:d] with: if d=n and symmetric then distance matrix assumed, otherwise: [1:n,1:d] matrix of defining the dataset that consists of `n` cases or d-dimensional data points. Every case has `d` attributes, variables or features. `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. `...` Additional parameters to be passed on to FUN

## Details

Applies a given function to each feature of each cluster of data using the clustering stored in `Cls` which is the cluster identifiers for all rows in data. If missing, all data are in first cluster, The main output is `FUNPerCluster[i]` which is the result of `FUN` for the data points in cluster of `UniqueClusters[i]` named with the function's name used.

In case of a distance matrix an automatic classical multidimensional scaling transformation of distances to data is computed. Number of dimensions is selected by the minimal stress w.r.t. the possible output dimensions of cmdscale.

If `FUN` has not function name, then ResultPerCluster is given back.

## Value

 `UniqueClusters` The unique clusters in Cls `FUNPerCluster` a matrix of [1:k,1:d] of d features and k clusters

## Author(s)

Felix Pape, Michael Thrun

## Examples

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35``` ```##one dataset data(Hepta) Data=Hepta\$Data Cls=Hepta\$Cls #mean per cluster ClusterApply(Data,mean,Cls) # 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) ```

FCPS documentation built on July 8, 2021, 1:06 a.m.