Learn R Programming

dendextendRcpp (version 0.6.1)

dendextendRcpp_heights_per_k.dendrogram: Which height will result in which k for a dendrogram

Description

This is the Rcpp version of the heights_per_k.dendrogram from the dendextend R package. It is intended to override that function in order to get a speed gain of ranging from 10 times faster (for a tree with 3 leaves), to 130 times (!) faster (for a tree with 150 leaves).

Usage

dendextendRcpp_heights_per_k.dendrogram(tree, ...)

Arguments

tree
a dendrogram.
...
not used.

Value

a vector of heights, with its names being the k clusters that will result for cutting the dendrogram at each height.

Examples

Run this code
## Not run: 
# 
# dend = as.dendrogram(hclust(dist(iris[1:150,-5])))
# 
# # plutral heightS
# dendextendRcpp_heights_per_k.dendrogram(dend,1)
# dendextendRcpp_heights_per_k.dendrogram(dend,.5)
# dendextendRcpp_heights_per_k.dendrogram(dend,0.05)
# dendextendRcpp_heights_per_k.dendrogram(dend,0)
# dendextendRcpp_heights_per_k.dendrogram(dend,-1)
# 
# dendextendRcpp_heights_per_k.dendrogram(dend,c(1,.5,.2,0,-1))
# 
# \dontrun{
# require(microbenchmark)
# dend = as.dendrogram(hclust(dist(iris[1:150,-5])))
# dend = as.dendrogram(hclust(dist(iris[1:30,-5])))
# dend = as.dendrogram(hclust(dist(iris[1:3,-5])))
# microbenchmark(
#    #    dendextendRcpp::heights_per_k.dendrogram(dend),
#    dendextendRcpp::dendextendRcpp_heights_per_k.dendrogram(dend),
#    dendextend::old_heights_per_k.dendrogram(dend)
# )
# # improvment is 10 times faster (in Rcpp) for a tree of size 3
# # 76 times faster for a tree of size 30
# # And:
# # 134 times faster for a tree of size 150!!
# }
# ## End(Not run)

Run the code above in your browser using DataLab