setwd('/users/daf/Current/courses/Probcourse/Clustering/RCode') wdat<-read.csv('turkiye-student-evaluation_R_Specific.csv') wdm<-wdat[c(1:20),c(7:9)] # choose the questions wdm2 <- matrix(as.vector(t(as.matrix(wdm))), nrow = 5, byrow = TRUE) foo<-kmeans((wdm2), 2) closest<-knn(foo$centers, wdm2, c(1:2)) wdm2<-as.data.frame(wdm2) wdm2$type<-closest bar<-subset(wdm2, (wdm2$type==1))