This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
# Load packages
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
# Import your survey
cluster_data <- read.csv("Group Survey Questionnaire_November 12, 2026_15.25 (1).csv")
# Select social media questions
cluster_data <- cluster_data %>%
select(Behavioral.Q1_1,
Behavioral.Q1_2,
Behavioral.Q1_3,
Behavioral.Q1_4)
# Convert to numeric
cluster_data <- cluster_data %>%
mutate(across(everything(), as.numeric))
## Warning: There were 4 warnings in `mutate()`.
## The first warning was:
## ℹ In argument: `across(everything(), as.numeric)`.
## Caused by warning:
## ! NAs introduced by coercion
## ℹ Run `dplyr::last_dplyr_warnings()` to see the 3 remaining warnings.
# Remove missing responses
cluster_data <- na.omit(cluster_data)
# Run cluster analysis
set.seed(123)
clusters <- kmeans(cluster_data, centers = 3)
# See results
clusters
## K-means clustering with 3 clusters of sizes 2, 2, 10
##
## Cluster means:
## Behavioral.Q1_1 Behavioral.Q1_2 Behavioral.Q1_3 Behavioral.Q1_4
## 1 3.0 4.0 4.0 1.5
## 2 3.5 1.5 1.5 3.5
## 3 1.1 1.9 3.7 3.5
##
## Clustering vector:
## 5 6 7 8 9 10 11 12 13 14 15 16 17 18
## 3 1 3 3 3 2 2 3 3 3 3 3 1 3
##
## Within cluster sum of squares by cluster:
## [1] 6.5 2.0 10.4
## (between_SS / total_SS = 66.5 %)
##
## Available components:
##
## [1] "cluster" "centers" "totss" "withinss" "tot.withinss"
## [6] "betweenss" "size" "iter" "ifault"