# import an excel file
mydata <- read_excel("C:/Users/Eneja/Desktop/anketa10.xlsx")
# delete first row in which the questions are written
mydata <- mydata[-1,]
# add an ID variable
mydata$ID <- 1:nrow(mydata)
mydata <- mydata[,c(93, 1:92)]
head(mydata)
## # A tibble: 6 × 93
## ID Q1 Q2 Q3 Q4 Q5 Q6a Q6b Q6c Q6d Q7a_1 Q7b_1 Q7c_1 Q7d_1 Q7e_1 Q7f_1 Q8a Q8b Q8c Q8d Q9a
## <int> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <chr> <chr> <chr> <chr> <chr>
## 1 1 7 2 -2 -2 -2 1 5 5 5 7 10 16 16 16 80 3 5 2 4 5
## 2 2 6 2 -2 -2 -2 3 4 5 3 0 22 59 0 23 57 4 4 1 4 5
## 3 3 5 2 -2 -2 -2 4 4 3 3 0 26 63 17 0 100 4 2 2 4 4
## 4 4 7 1 3 4 2 5 4 3 2 82 0 85 63 85 100 5 4 1 4 5
## 5 5 7 2 -2 -2 -2 4 2 4 5 0 0 0 0 25 50 5 1 1 1 5
## 6 6 7 1 3 4 2 4 4 4 2 0 0 -1 0 0 70 4 4 1 2 5
## # … with 72 more variables: Q9b <chr>, Q9c <chr>, Q9d <chr>, Q10a <chr>, Q10b <chr>, Q10c <chr>, Q10d <chr>, Q10e <chr>,
## # Q10f <chr>, Q10g <chr>, Q10h <chr>, Q11 <chr>, Q11_9_text <chr>, Q12a <chr>, Q12b <chr>, Q12c <chr>, Q12d <chr>, Q12e <chr>,
## # Q12f <chr>, Q13a <chr>, Q13b <chr>, Q13c <chr>, Q13d <chr>, Q13e <chr>, Q14a <chr>, Q14b <chr>, Q14c <chr>, Q14d <chr>,
## # Q14e <chr>, Q15a <chr>, Q15b <chr>, Q15c <chr>, Q15d <chr>, Q15e <chr>, Q16a <chr>, Q16b <chr>, Q16c <chr>, Q16d <chr>,
## # Q16e <chr>, Q17a <chr>, Q17b <chr>, Q17c <chr>, Q17d <chr>, Q17e <chr>, Q18a <chr>, Q18b <chr>, Q18c <chr>, Q18d <chr>,
## # Q18e <chr>, Q19 <chr>, Q20 <chr>, Q21 <chr>, Q22 <chr>, Q22_4_text <chr>, Q23 <chr>, Q24a <chr>, Q24b <chr>, Q24c <chr>,
## # Q24d <chr>, Q24e <chr>, Q24f <chr>, Q24g <chr>, Q24h <chr>, Q24i <chr>, Q24j <chr>, Q24k <chr>, Q24l <chr>, …
Description:
#For those who did not move only one slider for question 7, insert 50 (midpoint - half savings, half loans) as the selected value
mydata$Q7a_1 <- ifelse((mydata$Q7a_1==-1)&(mydata$Q7b_1!=-1)&(mydata$Q7c_1!=-1)&(mydata$Q7d_1!=-1)&(mydata$Q7e_1!=-1)&(mydata$Q7f_1!=-1),50, mydata$Q7a_1)
mydata$Q7b_1 <- ifelse((mydata$Q7a_1!=-1)&(mydata$Q7b_1==-1)&(mydata$Q7c_1!=-1)&(mydata$Q7d_1!=-1)&(mydata$Q7e_1!=-1)&(mydata$Q7f_1!=-1),50,mydata$Q7b_1)
mydata$Q7c_1 <- ifelse((mydata$Q7a_1!=-1)&(mydata$Q7b_1!=-1)&(mydata$Q7c_1==-1)&(mydata$Q7d_1!=-1)&(mydata$Q7e_1!=-1)&(mydata$Q7f_1!=-1),50,mydata$Q7c_1)
mydata$Q7d_1 <- ifelse((mydata$Q7a_1!=-1)&(mydata$Q7b_1!=-1)&(mydata$Q7c_1!=-1)&(mydata$Q7d_1==-1)&(mydata$Q7e_1!=-1)&(mydata$Q7f_1!=-1),50,mydata$Q7d_1)
mydata$Q7e_1 <- ifelse((mydata$Q7a_1!=-1)&(mydata$Q7b_1!=-1)&(mydata$Q7c_1!=-1)&(mydata$Q7d_1!=-1)&(mydata$Q7e_1==-1)&(mydata$Q7f_1!=-1),50,mydata$Q7e_1)
mydata$Q7f_1 <- ifelse((mydata$Q7a_1!=-1)&(mydata$Q7b_1!=-1)&(mydata$Q7c_1!=-1)&(mydata$Q7d_1!=-1)&(mydata$Q7e_1!=-1)&(mydata$Q7f_1==-1),50,mydata$Q7f_1)
#Identify values -1,-3 and replace them with NA. Identify also the -2
# -1 means: The person has not answered the specific question
# -2 means: Person did not respond because it did not satisfy if sentence
# -3 means: Person stopped answering questionnaire before coming to this sentence
mydata[mydata == -1] <- NA
mydata[mydata == -3] <- NA
# Get rid of those that are under 18 and over 27
mydata_t1<-mydata[!(mydata$Q2=="-2"),]
#solve some problems with 1ka (illogical -2 values)
mydata_t1 <- mydata_t1[!(mydata_t1$Q13a=="-2"),]
mydata_dropNA<-mydata_t1
mydata_dropNA <- na.omit(mydata_dropNA)
# convert character to integer, except the variables where Other was typed in
mydata_dropNA <- mydata_dropNA %>%
mutate_at(c(2:33), as.integer)
mydata_dropNA <- mydata_dropNA %>%
mutate_at(c(35:74), as.integer)
mydata_dropNA <- mydata_dropNA %>%
mutate_at(c(76:88), as.integer)
mydata_dropNA <- mydata_dropNA %>%
mutate_at(c(89:93), as.integer)
## Warning in mask$eval_all_mutate(quo): NAs introduced by coercion
mydata_dropNA$Q1 <- mydata_dropNA$Q1 + 16
Transform fo factors
mydata_dropNA$Sex_F <- factor(mydata_dropNA$Q19,
levels = c(1, 2,3),
labels = c("Female", "Male", "Other"))
mydata_dropNA$Region_F <- factor(mydata_dropNA$Q20,
levels = c(1,2, 3, 4, 5, 6, 7, 8, 9),
labels = c("Ljubljana z okolico","Štajerska","Prekmurje", "Dolenjska","Primorska" , "Gorenjska" , "Goriška", "Koroška" , "Notranjska"))
mydata_dropNA$Status_F <- factor(mydata_dropNA$Q22,
levels = c(1,2, 3),
labels = c("Single","In a relationship","Married"))
mydata_dropNA$Children_F <- factor(mydata_dropNA$Q23,
levels = c(2, 1),
labels = c("No", "Yes"))
mydata_dropNA$Education_F <- factor(mydata_dropNA$Q25,
levels = c(1,2,3,4,5),
labels = c("Primary school", "High school", "Vocational School", "Undergraduate", "Post-Graduate"))
mydata_dropNA$Employed_F <- factor(mydata_dropNA$Q26,
levels = c(2, 1),
labels = c("No", "Yes"))
head(mydata_dropNA)
## # A tibble: 6 × 99
## ID Q1 Q2 Q3 Q4 Q5 Q6a Q6b Q6c Q6d Q7a_1 Q7b_1 Q7c_1 Q7d_1 Q7e_1 Q7f_1 Q8a Q8b Q8c Q8d Q9a
## <int> <dbl> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int>
## 1 1 23 2 -2 -2 -2 1 5 5 5 7 10 16 16 16 80 3 5 2 4 5
## 2 2 22 2 -2 -2 -2 3 4 5 3 0 22 59 0 23 57 4 4 1 4 5
## 3 3 21 2 -2 -2 -2 4 4 3 3 0 26 63 17 0 100 4 2 2 4 4
## 4 4 23 1 3 4 2 5 4 3 2 82 0 85 63 85 100 5 4 1 4 5
## 5 5 23 2 -2 -2 -2 4 2 4 5 0 0 0 0 25 50 5 1 1 1 5
## 6 6 23 1 3 4 2 4 4 4 2 0 0 50 0 0 70 4 4 1 2 5
## # … with 78 more variables: Q9b <int>, Q9c <int>, Q9d <int>, Q10a <int>, Q10b <int>, Q10c <int>, Q10d <int>, Q10e <int>,
## # Q10f <int>, Q10g <int>, Q10h <int>, Q11 <int>, Q11_9_text <chr>, Q12a <int>, Q12b <int>, Q12c <int>, Q12d <int>, Q12e <int>,
## # Q12f <int>, Q13a <int>, Q13b <int>, Q13c <int>, Q13d <int>, Q13e <int>, Q14a <int>, Q14b <int>, Q14c <int>, Q14d <int>,
## # Q14e <int>, Q15a <int>, Q15b <int>, Q15c <int>, Q15d <int>, Q15e <int>, Q16a <int>, Q16b <int>, Q16c <int>, Q16d <int>,
## # Q16e <int>, Q17a <int>, Q17b <int>, Q17c <int>, Q17d <int>, Q17e <int>, Q18a <int>, Q18b <int>, Q18c <int>, Q18d <int>,
## # Q18e <int>, Q19 <int>, Q20 <int>, Q21 <int>, Q22 <int>, Q22_4_text <chr>, Q23 <int>, Q24a <int>, Q24b <int>, Q24c <int>,
## # Q24d <int>, Q24e <int>, Q24f <int>, Q24g <int>, Q24h <int>, Q24i <int>, Q24j <int>, Q24k <int>, Q24l <int>, …
#mydata_dropNA <- mydata_dropNA[-c(255, 231, 107, 180, 188, 124),]
mydata_dropNA <- mydata_dropNA[-c(255, 231, 107),]
summary(mydata_dropNA[c("Q12a", "Q6a", "Q6c", "Q12d","Q12f")])
## Q12a Q6a Q6c Q12d Q12f
## Min. :1.000 Min. :1.000 Min. :1.000 Min. :1.000 Min. :1.000
## 1st Qu.:2.000 1st Qu.:2.000 1st Qu.:4.000 1st Qu.:4.000 1st Qu.:3.000
## Median :3.000 Median :3.000 Median :4.000 Median :4.000 Median :3.000
## Mean :2.709 Mean :2.997 Mean :4.206 Mean :3.977 Mean :3.268
## 3rd Qu.:3.000 3rd Qu.:4.000 3rd Qu.:5.000 3rd Qu.:5.000 3rd Qu.:4.000
## Max. :5.000 Max. :5.000 Max. :5.000 Max. :5.000 Max. :5.000
library(Hmisc)
rcorr(as.matrix(mydata_dropNA[ , c("Q12a", "Q6a", "Q6c", "Q9a","Q12f")]),
type = "pearson")
## Q12a Q6a Q6c Q9a Q12f
## Q12a 1.00 -0.01 -0.05 0.16 0.34
## Q6a -0.01 1.00 -0.24 0.17 0.08
## Q6c -0.05 -0.24 1.00 -0.02 -0.02
## Q9a 0.16 0.17 -0.02 1.00 0.18
## Q12f 0.34 0.08 -0.02 0.18 1.00
##
## n= 306
##
##
## P
## Q12a Q6a Q6c Q9a Q12f
## Q12a 0.8613 0.3605 0.0040 0.0000
## Q6a 0.8613 0.0000 0.0033 0.1847
## Q6c 0.3605 0.0000 0.6685 0.6755
## Q9a 0.0040 0.0033 0.6685 0.0018
## Q12f 0.0000 0.1847 0.6755 0.0018
“Q12a”, “Q6a”, “Q6c”, “Q12d”,“Q12f” najboljšiii
mydata_std <- as.data.frame(scale(mydata_dropNA[c("Q12a", "Q6a", "Q6c", "Q9a","Q12f")]))
mydata_std$Dissimilarity <- sqrt(mydata_std$Q12a^2 + mydata_std$Q6a^2 + mydata_std$Q6c^2 + mydata_std$Q9a^2 + mydata_std$Q12f^2)
head(mydata_std[order(-mydata_std$Dissimilarity), ], 5) #Finding top 5 objects with highest value of dissimilarity
## Q12a Q6a Q6c Q9a Q12f Dissimilarity
## 232 -1.8401698 -1.7242879 0.9307424 -3.6738141 -1.3475885 4.747481
## 249 -1.8401698 -1.7242879 0.9307424 -3.6738141 0.7779893 4.618209
## 16 -1.8401698 -0.8607329 0.9307424 -3.6738141 -1.3475885 4.506248
## 149 -0.7635121 0.8663771 -3.7574417 0.6750722 -1.3475885 4.209946
## 293 1.3898032 -0.8607329 -3.7574417 0.6750722 -0.2847996 4.162645
mydata1 <- mydata_std
library(factoextra)
#Finding Eudlidean distances, based on 6 Cluster variables, then saving them into object Distances
Distances <- get_dist(mydata1,
method = "euclidian")
Distances2 <- Distances^2
fviz_dist(Distances2) #Showing matrix of distances
library(factoextra)
get_clust_tendency(mydata1, #Hopkins statistics
n = nrow(mydata1) - 1,
graph = FALSE)
## $hopkins_stat
## [1] 0.6471483
##
## $plot
## NULL
library(dplyr)
WARD <- mydata1 %>% #Selecting variables
get_dist(method = "euclidean") %>% #Selecting distance
hclust(method = "ward.D2") #Selecting algorithm
WARD
##
## Call:
## hclust(d = ., method = "ward.D2")
##
## Cluster method : ward.D2
## Distance : euclidean
## Number of objects: 306
library(factoextra)
fviz_dend(WARD) #Dendrogram
## Warning: The `<scale>` argument of `guides()` cannot be `FALSE`. Use "none" instead as of ggplot2 3.3.4.
## ℹ The deprecated feature was likely used in the factoextra package.
## Please report the issue at <]8;;https://github.com/kassambara/factoextra/issueshttps://github.com/kassambara/factoextra/issues]8;;>.
set.seed(1)
#install.packages("NbClust")
library(NbClust)
OptNumber <- mydata1[c("Q12a", "Q6a", "Q6c", "Q9a","Q12f")] %>%
#scale() %>%
NbClust(distance = "euclidean",
min.nc = 2, max.nc = 10,
method = "ward.D2",
index = "all")
## *** : The Hubert index is a graphical method of determining the number of clusters.
## In the plot of Hubert index, we seek a significant knee that corresponds to a
## significant increase of the value of the measure i.e the significant peak in Hubert
## index second differences plot.
##
## *** : The D index is a graphical method of determining the number of clusters.
## In the plot of D index, we seek a significant knee (the significant peak in Dindex
## second differences plot) that corresponds to a significant increase of the value of
## the measure.
##
## *******************************************************************
## * Among all indices:
## * 5 proposed 2 as the best number of clusters
## * 2 proposed 3 as the best number of clusters
## * 7 proposed 4 as the best number of clusters
## * 2 proposed 5 as the best number of clusters
## * 1 proposed 6 as the best number of clusters
## * 6 proposed 10 as the best number of clusters
##
## ***** Conclusion *****
##
## * According to the majority rule, the best number of clusters is 4
##
##
## *******************************************************************
mydata1$ClusterWard <- cutree(WARD,
k = 4) #Number of groups
head(mydata1[c( "ClusterWard")])
## ClusterWard
## 1 1
## 2 1
## 3 2
## 4 3
## 5 1
## 6 3
#Calculating positions of initial leaders
Initial_leaders <- aggregate(mydata1[, c("Q12a", "Q6a", "Q6c", "Q9a","Q12f")],
by = list(mydata1$ClusterWard),
FUN = mean)
Initial_leaders
## Group.1 Q12a Q6a Q6c Q9a Q12f
## 1 1 0.2663343 -0.2224531 0.24917219 0.2378201 0.4025475
## 2 2 0.3900496 0.7430121 -2.20866656 0.4032668 0.3604651
## 3 3 -0.7798251 0.3953471 0.25592805 0.2302998 -1.0899428
## 4 4 -0.3020874 -0.2130667 -0.03200966 -2.5089338 -0.4366266
library(factoextra)
kmeans_clu <- hkmeans(mydata1, #Data
k = 4, #Number of groups
hc.metric = "euclidean", #Distance for hierar. clus.
hc.method = "ward.D2") #Algorithm for hierar. clus.
kmeans_clu
## Hierarchical K-means clustering with 4 clusters of sizes 180, 36, 62, 28
##
## Cluster means:
## Q12a Q6a Q6c Q9a Q12f Dissimilarity ClusterWard
## 1 0.2652941 -0.2658395 0.26007165 0.2281034 0.3764912 1.730436 1
## 2 0.2832384 0.8903647 -1.90170213 0.4032668 0.4237263 2.862931 2
## 3 -0.7982430 0.3510297 0.36362339 0.2366764 -1.1418875 2.159150 3
## 4 -0.3020874 -0.2130667 -0.03200966 -2.5089338 -0.4366266 3.144452 4
##
## Clustering vector:
## [1] 1 1 2 2 1 3 1 1 4 2 1 1 2 2 1 4 4 4 1 1 1 1 3 1 1 1 2 1 1 3 3 1 1 1 1 1 2 2 4 1 3 3 1 1 1 1 1 2 1 1 3 1 1 4 4 1 4 4 4 3 1 4
## [63] 1 2 2 2 1 1 1 1 1 2 1 1 1 2 1 1 1 1 3 1 1 2 4 2 1 1 1 1 1 1 1 1 3 1 1 1 1 1 1 2 1 1 1 1 2 1 1 1 1 1 1 1 3 4 3 1 3 1 1 4 3 1
## [125] 1 2 1 1 1 1 3 1 1 1 2 1 1 3 3 1 3 1 1 1 4 4 1 1 2 1 3 1 1 1 3 1 1 2 1 1 1 1 1 1 4 1 3 1 3 3 1 1 1 1 4 1 1 3 3 3 1 3 1 3 1 1
## [187] 3 2 1 1 1 1 1 3 1 3 2 1 1 1 4 3 1 2 1 1 1 3 1 3 1 1 4 2 1 4 1 3 1 3 1 1 1 3 4 1 1 1 4 1 1 4 3 1 1 1 3 1 1 3 3 1 3 4 1 3 1 2
## [249] 4 3 1 1 1 1 1 1 1 2 1 1 1 3 3 1 2 3 1 3 1 1 3 2 4 1 1 1 1 3 3 3 1 3 2 1 3 3 3 1 3 2 3 1 2 3 3 3 2 2 1 2 1 1 4 1 3 1
##
## Within cluster sum of squares by cluster:
## [1] 586.9983 155.3218 200.4800 143.7585
## (between_SS / total_SS = 47.7 %)
##
## Available components:
##
## [1] "cluster" "centers" "totss" "withinss" "tot.withinss" "betweenss" "size" "iter"
## [9] "ifault" "data" "hclust"
library(factoextra)
fviz_cluster(kmeans_clu,
palette = "Set1",
repel = FALSE,
ggtheme = theme_bw())
mydata1$ClusterK_Means <- kmeans_clu$cluster
head(mydata1[c( "ClusterWard", "ClusterK_Means")])
## ClusterWard ClusterK_Means
## 1 1 1
## 2 1 1
## 3 2 2
## 4 3 2
## 5 1 1
## 6 3 3
#Checking for reclassifications
table(mydata1$ClusterWard)
##
## 1 2 3 4
## 184 28 66 28
table(mydata1$ClusterK_Means)
##
## 1 2 3 4
## 180 36 62 28
table(mydata1$ClusterWard, mydata1$ClusterK_Means)
##
## 1 2 3 4
## 1 180 4 0 0
## 2 0 28 0 0
## 3 0 4 62 0
## 4 0 0 0 28
Centroids <- kmeans_clu$centers
Centroids
## Q12a Q6a Q6c Q9a Q12f Dissimilarity ClusterWard
## 1 0.2652941 -0.2658395 0.26007165 0.2281034 0.3764912 1.730436 1
## 2 0.2832384 0.8903647 -1.90170213 0.4032668 0.4237263 2.862931 2
## 3 -0.7982430 0.3510297 0.36362339 0.2366764 -1.1418875 2.159150 3
## 4 -0.3020874 -0.2130667 -0.03200966 -2.5089338 -0.4366266 3.144452 4
library(ggplot2)
library(tidyr)
##
## Attaching package: 'tidyr'
## The following object is masked from 'package:magrittr':
##
## extract
Figure <- as.data.frame(Centroids)
Figure$id <- 1:nrow(Figure)
Figure <- pivot_longer(Figure, cols = c(Q12a, Q6a, Q6c, Q9a,Q12f))
Figure$Groups <- factor(Figure$id,
levels = c(1, 2, 3, 4, 5),
labels = c("1", "2", "3", "4", "5"))
Figure$nameFactor <- factor(Figure$name,
levels = c("Q12a", "Q6a", "Q6c", "Q9a","Q12f"),
labels = c("Reputation", "Necessity", "Postponing", "Large_amount", "Transparency"))
ggplot(Figure, aes(x = nameFactor, y = value)) +
geom_hline(yintercept = 0) +
theme_bw() +
geom_point(aes(shape = Groups, col = Groups), size = 3) +
geom_line(aes(group = id), linewidth = 1) +
ylab("Averages") +
xlab("Cluster variables")+
ylim(-2.7, 1.0)
#Checking if clustering variables successfully differentiate between groups
fit <- aov(cbind(Q12a, Q6a, Q6c, Q9a,Q12f) ~ as.factor(ClusterK_Means),
data = mydata1)
summary(fit)
## Response Q12a :
## Df Sum Sq Mean Sq F value Pr(>F)
## as.factor(ClusterK_Means) 3 57.618 19.2059 23.446 1.139e-13 ***
## Residuals 302 247.382 0.8191
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Response Q6a :
## Df Sum Sq Mean Sq F value Pr(>F)
## as.factor(ClusterK_Means) 3 50.171 16.7235 19.819 9.388e-12 ***
## Residuals 302 254.829 0.8438
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Response Q6c :
## Df Sum Sq Mean Sq F value Pr(>F)
## as.factor(ClusterK_Means) 3 150.59 50.198 98.181 < 2.2e-16 ***
## Residuals 302 154.41 0.511
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Response Q9a :
## Df Sum Sq Mean Sq F value Pr(>F)
## as.factor(ClusterK_Means) 3 194.95 64.982 178.32 < 2.2e-16 ***
## Residuals 302 110.05 0.364
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Response Q12f :
## Df Sum Sq Mean Sq F value Pr(>F)
## as.factor(ClusterK_Means) 3 118.16 39.386 63.661 < 2.2e-16 ***
## Residuals 302 186.84 0.619
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
aggregate(mydata_dropNA$Q28,
by = list(mydata1$ClusterK_Means),
FUN = "mean")
## Group.1 x
## 1 1 2.272222
## 2 2 1.583333
## 3 3 2.000000
## 4 4 2.500000
fit <- aov(mydata_dropNA$Q28 ~ as.factor(ClusterK_Means),
data = mydata1)
summary(fit)
## Df Sum Sq Mean Sq F value Pr(>F)
## as.factor(ClusterK_Means) 3 19.1 6.353 3.212 0.0233 *
## Residuals 302 597.4 1.978
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
aggregate(mydata_dropNA$Q24b,
by = list(mydata1$ClusterK_Means),
FUN = "mean")
## Group.1 x
## 1 1 0.4333333
## 2 2 0.5000000
## 3 3 0.4354839
## 4 4 0.3571429
aggregate(mydata_dropNA$Q25,
by = list(mydata1$ClusterK_Means),
FUN = "mean")
## Group.1 x
## 1 1 3.366667
## 2 2 3.472222
## 3 3 3.096774
## 4 4 3.071429
aggregate(mydata_dropNA$Q9a,
by = list(mydata1$ClusterK_Means),
FUN = "mean")
## Group.1 x
## 1 1 4.588889
## 2 2 4.750000
## 3 3 4.596774
## 4 4 2.071429
aggregate(mydata_dropNA$Q22,
by = list(mydata1$ClusterK_Means),
FUN = "mean")
## Group.1 x
## 1 1 1.527778
## 2 2 1.444444
## 3 3 1.580645
## 4 4 1.642857
aggregate(mydata_dropNA$Q10h,
by = list(mydata1$ClusterK_Means),
FUN = "mean")
## Group.1 x
## 1 1 3.850000
## 2 2 4.222222
## 3 3 4.193548
## 4 4 3.321429