Description Usage Arguments See Also Examples
This function passes a data.frame, formula, and additional arguments to
kmeans
.
1 2 3 4 |
data |
Data frame (or object that can be coerced to one) containing the variables in the model |
formula |
A |
... |
Additional arguments to pass to model function |
object |
Fitted model |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | # Standard kmeans
kmeans(iris, centers = 3)
# formula interface can be used to select certain variables
kmeans(iris, ~ Petal.Width + Sepal.Width, centers = 3)
#... or create new variables. Consider non-linear example:
# Create data for two circles
x <- matrix(rnorm(300),nc=2)
y <- x/sqrt(rowSums(x^2))
d <- data.frame(rbind(y, y*5))
plot(d)
fit <- kmeans(d, centers = 2)
plot(d, col = predict(fit, d))
fit <- kmeans(d, ~ X1 + X2 + I(X1^2 + X2^2), centers = 2)
plot(d, col = predict(fit, d))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.