knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "README-" )
This package provides R binding to a cpp implementation of the kmeans++ algorithm.
You can install the released version of tglkmeans using the following command:
install.packages("tglkmeans")
Or install the development version using:
if (!require("remotes")) install.packages("remotes") remotes::install_github("tanaylab/tglkmeans")
library(tglkmeans)
Create 5 clusters normally distributed around 1 to 5, with sd of 0.3:
data <- rbind( matrix(rnorm(100, mean = 1, sd = 0.3), ncol = 2), matrix(rnorm(100, mean = 2, sd = 0.3), ncol = 2), matrix(rnorm(100, mean = 3, sd = 0.3), ncol = 2), matrix(rnorm(100, mean = 4, sd = 0.3), ncol = 2), matrix(rnorm(100, mean = 5, sd = 0.3), ncol = 2) ) colnames(data) <- c("x", "y") head(data)
Cluster using kmeans++:
km <- TGL_kmeans(data, k = 5, id_column = FALSE) km
Plot the results:
plot(data, col = km$cluster) points(km$centers, pch = 8, cex = 2)
Please refer to the package vignettes for usage and workflow, or look at the usage section in the site.
browseVignettes("usage")
From version 0.4.0 onward, the package uses R random number generation functions instead of the C++11 random number generation functions. Note that this may result in different results from previous versions. To get the same results as previous versions, set the use_cpp_random
argument to TRUE
in the TGL_kmeans
function.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.