A dendrogram object in R are is a list structure with attributes in its nodes and leaves.
Working with dendrogram objects often require a function to recursively go through all (or most) element in the list object. Naturally, such function are rather slow in R, but can become much faster thank to Rcpp.
This package offers faster manipulation of dendrogram objects in R.
To install the stable version on CRAN:
install.packages('dendextendRcpp')
To install the cutting-edge GitHub version:
if (!require('devtools')) install.packages('devtools');
devtools::install_github('talgalili/dendextendRcpp')
library(dendextendRcpp)
hc <- hclust(dist(USArrests))
dend <- as.dendrogram(hc)
labels(dend)
require(microbenchmark)
microbenchmark(stats_labels.dendrogram(dend),
dendextendRcpp::dendextendRcpp_labels.dendrogram(dend),
times = 100)
# about 10-30 times faster. It is faster the larger the tree is.
You are welcome to:
Visit the Rcpp project!
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.