knitr::opts_chunk$set(echo = TRUE)
library(readxl)
library(leaps)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.5.1 ✔ tibble 3.2.1
## ✔ lubridate 1.9.4 ✔ tidyr 1.3.1
## ✔ purrr 1.0.4
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
data_wahyu <- read_excel("C:/Users/User/Downloads/data wahyu.xlsx")
data_wahyu
## # A tibble: 8 × 6
## objek Diameter Kerapatan Volume TBC Ttot
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 a 0.21 0.04 0.35 8.5 18
## 2 b 0.2 0.04 0.31 8.15 18.0
## 3 c 0.15 0.05 0.19 7.12 11.3
## 4 d 0.15 0.05 0.22 7.55 13.8
## 5 e 0.15 0.05 0.32 6.84 12.8
## 6 f 0.25 0.04 0.42 6.79 12.8
## 7 g 0.19 0.05 0.19 8.07 10.5
## 8 h 0.18 0.05 0.17 7.07 10.1
df<-column_to_rownames(data_wahyu,"objek")
data<-as.matrix.data.frame(df[1:5])
data
## Diameter Kerapatan Volume TBC Ttot
## a 0.21 0.04 0.35 8.50 18.00
## b 0.20 0.04 0.31 8.15 17.96
## c 0.15 0.05 0.19 7.12 11.33
## d 0.15 0.05 0.22 7.55 13.82
## e 0.15 0.05 0.32 6.84 12.79
## f 0.25 0.04 0.42 6.79 12.85
## g 0.19 0.05 0.19 8.07 10.50
## h 0.18 0.05 0.17 7.07 10.09
summary(data)
## Diameter Kerapatan Volume TBC
## Min. :0.1500 Min. :0.04000 Min. :0.1700 Min. :6.790
## 1st Qu.:0.1500 1st Qu.:0.04000 1st Qu.:0.1900 1st Qu.:7.013
## Median :0.1850 Median :0.05000 Median :0.2650 Median :7.335
## Mean :0.1850 Mean :0.04625 Mean :0.2712 Mean :7.511
## 3rd Qu.:0.2025 3rd Qu.:0.05000 3rd Qu.:0.3275 3rd Qu.:8.090
## Max. :0.2500 Max. :0.05000 Max. :0.4200 Max. :8.500
## Ttot
## Min. :10.09
## 1st Qu.:11.12
## Median :12.82
## Mean :13.42
## 3rd Qu.:14.86
## Max. :18.00
heatmap(data,scale = "column", margins = c(8, 6) )
hasil_kmeans <- kmeans(data,centers=3)
hasil_kmeans
## K-means clustering with 3 clusters of sizes 3, 2, 3
##
## Cluster means:
## Diameter Kerapatan Volume TBC Ttot
## 1 0.1733333 0.05000000 0.1833333 7.420 10.64000
## 2 0.2050000 0.04000000 0.3300000 8.325 17.98000
## 3 0.1833333 0.04666667 0.3200000 7.060 13.15333
##
## Clustering vector:
## a b c d e f g h
## 2 2 1 3 3 3 1 1
##
## Within cluster sum of squares by cluster:
## [1] 1.434333 0.062900 1.056600
## (between_SS / total_SS = 96.3 %)
##
## Available components:
##
## [1] "cluster" "centers" "totss" "withinss" "tot.withinss"
## [6] "betweenss" "size" "iter" "ifault"
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.