Panggil semua packages dengan fungsi library (nama_packages)

library(wordcloud)
## Loading required package: RColorBrewer
library(tm)
## Loading required package: NLP
library(textclean)
library(tidytext)
library(ggplot2)
## 
## Attaching package: 'ggplot2'
## The following object is masked from 'package:NLP':
## 
##     annotate
library(parallel)
library(tokenizers)
library(tau)
library(NLP)
library(stringr)
library(devtools)
## Loading required package: usethis
library(quanteda)
## Package version: 3.3.1
## Unicode version: 13.0
## ICU version: 69.1
## Parallel computing: 4 of 4 threads used.
## See https://quanteda.io for tutorials and examples.
## 
## Attaching package: 'quanteda'
## The following object is masked from 'package:tm':
## 
##     stopwords
## The following objects are masked from 'package:NLP':
## 
##     meta, meta<-
library(kayadata)
library(syuzhet)
library(e1071)
library(sentimentr)
## 
## Attaching package: 'sentimentr'
## The following object is masked from 'package:syuzhet':
## 
##     get_sentences
library(SentimentAnalysis)
## 
## Attaching package: 'SentimentAnalysis'
## The following object is masked from 'package:base':
## 
##     write
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
library(pacman)
pacman::p_load(textstem, dplyr)

TENTANG DATASET

_Dataset yang digunakan adalah data yang diperoleh dari hasil crowling data di twitter. data ini berisi 100 lebih tweets tentang Prabowo atasi stunting

Import data ke dalam R untuk dilakukan analisis

setwd("C:/Users/kjl/Documents/Tugas Kuliah")
Prabowo.atasi.stunting <- read.csv("~/Tugas Kuliah/Prabowo-atasi-stunting.csv", sep=";")
tweets<-Prabowo.atasi.stunting$full_text
head(tweets)
## [1] "@prabowo Bos BUMN, Erick Thohir, bakal seru nemenin Prabowo di Pilpres 2024! dekade08"                                                                                                  
## [2] "@prabowo Erick Thohir, eks teknokrat BUMN, bisa jadi tandem oke buat Prabowo di Pilpres 2024! dekade08"                                                                                 
## [3] "@prabowo Selain relawan Pro Jokowi yang resmi mendeklarasikan dukungan untuk sang Ketua Umum Partai Gerindra itu, relawan Konco Prabowo Subianto juga menyampaikan hal senada. dekade08"
## [4] "@prabowo Selain relawan Pro Jokowi yang resmi mendeklarasikan dukungan untuk sang Ketua Umum Partai Gerindra itu, relawan Konco Prabowo juga menyampaikan hal senada. dekade08"         
## [5] "@prabowo Erick Thohir, mantan Menteri BUMN, bisa jadi jagoan Prabowo Subianto di Pilpres 2024! dekade08"                                                                                
## [6] "@prabowo Baliho bergambar Prabowo Subianto bersama Gibran Rakabuming Raka bertebaran di Banyumas, Jawa Tengah. dekade08"

##duplikat

#duplicate
tweets <- skripsi%>% 
  as.data.frame() %>% 
  distinct()
tweets

##jumlah baris tweet setelah duplikat dihapus

nrow(tweets)
## NULL

##hapus url

tweets <- tweets %>% 
  replace_html() %>%   
  replace_url()
tweets

tweets <- strip(tweets)
head(tweets)

##stemming/lemmatizing = kata dasar

#stemming/lemmatizing = kata dasar
stem_strings(tweets)

##cetak tweet dengan html yang dikonversi di index

replace_html(replace_emoji(tweets))

melakukan tugas penggantian seluruh variabel teks

tweets <- tweets %>% 
  replace_emoji(.) %>% 
  replace_html(.)

hapus mentions

tweets <- tweets %>% 
  replace_tag(tweets, pattern = "@([A-Za-z0-9_]+)",replacement="") %>%  # remove mentions
  replace_hash(tweets, pattern = "#([A-Za-z0-9_]+)",replacement="")      # remove hashtags
tweets

##strip simbol

tweets <- strip(tweets)

##menghapus kata penghubung atau kata yang tidak baku

tweets <-removeWords(tweets, c("di","dan","yang","akan","agar","seperti","yaitu","kami","kami",
                         "mari","pada","jelang","dimana","dengan","sudah","ini","seluruh",
                         "diminta","tak","itu","hai","bisa","wib","oleh","mai","jam", "aug",
                         "masa","berikut","kalau","klik","ibodwq","terd","httpstconvv","tue","wed",
                         "httpstcoxu","yzmrlyx","tahapan","refaabdi","kota","kpu","kpuid","rt","hingga",
                         "saat", "belum","apa","sih","suara","pesta","dindap","http","httpstco",
                         "asn","bakal","wkwk","wkwkw","aug","iya","uu","i","ada","ngene","yang","bjir",
                         "ðÿðÿ","un","anjir","tahi","tbtb","my","wios","sialan","wkwkwkwk","sip","omo",
                         "like","plss","ket","e","after","ha","pakðÿ", "but","rill","cashback",
                         "allah","and","o","ðÿ'^ðÿ","nya","ya","ðÿ","no","nuruk","ki","jir",
                         "anjing","biar","kagak","sayang","mah","anjay","ngaruh","kalo","gua","thesis",
                         "skripsiðÿ","duh","ih","ots","a","pft","plis","plan","ra","rabi","o", 
                         "skripshit","duit","sih","nih", "amp", "ï","tuh","tau","â","â","aaaa","deh","ðÿº",
                         "coba","dll","iki","gue","kena","oon","pas","sad","up","wkwkwk","waleh","ajg",
                         "ah","adaâ","alaala","alah","alamðÿ","allahâ","ayo","end","bu","biak","is"))
head(rev)
##                   
## 1 function (x)    
## 2 UseMethod("rev")

lower case = mengubah huruf kapital menjadi huruf kecil

tweets <- tolower(tweets)
tweets

##Mengembalikan Kata yang disingkat Menjadi Kata Aslinya

tweets <- replace_contraction(tweets)
tweets

###Mengembalikan Kata yang Mengalami Perpanjangan Menjadi Kata Aslinya

tweets <- replace_word_elongation(tweets)
tweets

Menyimpang data yang sudah dibersihkan

write.csv(rev,file = "C:/Users/kjl/Documents/data-bersih3.csv", row.names = F) 

Mengubah Data Frame Menjadi Data Faktor

tdm <- TermDocumentMatrix(tweets)
m <- as.matrix(tdm)
v <- sort(rowSums(m),decreasing = TRUE)

##Mengubah Data Faktor Menjadi Data Frame

d <- data.frame(word = names(v), freq = v)

Membuast Diagram Worcloud

wordcloud(d$word, d$freq,
          random.order = FALSE,
          max.words = 500,
          colors = brewer.pal(name="Dark2",8))

tdm <-TermDocumentMatrix (tweets,
                        control = list(wordLengths= c (1, inf)))
tdm

periksa kata-kata yang sering muncul

(freq.terms <- findFreqTerms(tdm, lowfreq = 14))
##  [1] "dekade"   "pilpres"  "prabowo"  "jadi"     "dukungan" "jokowi"  
##  [7] "partai"   "resmi"    "gibran"   "projo"    "fahri"    "hamzah"
term.freq <- rowSums(as.matrix(tdm))
term.freq <- subset(term.freq, term.freq >= 14)
df <- data.frame(term = names(term.freq), freq = term.freq)
ggplot(df, aes(x = term, y = freq)) + geom_bar(stat = "identity") +
  xlab("Terms") + ylab("Count") + coord_flip()

##Menghapus istilah-istilah yang jarang?

tdm2 <- removeSparseTerms(tdm, sparse = 0.95)
m2 <- as.matrix(tdm2)

ANALISIS CLUSTER HIERARKI

distMatrix <- dist(scale (m2))
fit <- hclust (distMatrix, method = "ward")
## The "ward" method has been renamed to "ward.D"; note new "ward.D2"
plot(fit) 
rect.hclust(fit, k = 4)

ANALISIS CLUSTER K-MEANS

m3 <- t(m2) # transpose the matrix to cluster documents (tweets)
m3
##      Terms
## Docs  dekade erick pilpres prabowo thohir buat jadi tandem dukungan gerindra
##   1        1     1       1       2      1    0    0      0        0        0
##   2        1     1       1       2      1    1    1      1        0        0
##   3        1     0       0       2      0    0    0      0        1        1
##   4        1     0       0       2      0    0    0      0        1        1
##   5        1     1       1       2      1    0    1      0        0        0
##   6        1     0       0       2      0    0    0      0        0        0
##   7        1     0       0       2      0    0    0      0        1        0
##   8        1     1       0       2      1    0    0      0        0        0
##   9        1     1       1       2      1    1    0      1        0        0
##   10       1     1       0       2      1    0    0      0        0        0
##   11       1     0       1       2      0    0    0      0        0        0
##   12       1     0       1       2      0    0    0      0        0        0
##   13       0     0       0       0      0    0    0      0        0        0
##   14       1     0       0       2      0    0    0      0        0        0
##   15       1     0       1       2      0    0    0      0        0        0
##   16       1     0       1       2      0    1    0      0        0        0
##   17       1     0       0       2      0    0    0      0        1        0
##   18       1     0       0       2      0    0    0      0        0        0
##   19       1     0       1       2      0    0    1      0        0        0
##   20       1     0       0       2      0    0    0      0        0        0
##   21       1     0       1       3      0    0    0      0        0        0
##   22       1     0       0       2      0    0    0      0        0        1
##   23       1     0       0       2      0    1    1      0        0        0
##   24       1     0       0       2      0    0    0      0        0        0
##   25       1     0       0       2      0    0    0      0        0        0
##   26       1     0       0       2      0    0    0      0        1        0
##   27       1     0       0       3      0    0    0      0        0        0
##   28       1     0       0       3      0    0    0      0        0        0
##   29       1     0       0       2      0    0    0      0        0        0
##   30       1     0       0       2      0    0    0      0        1        0
##   31       1     0       1       2      0    0    0      0        0        0
##   32       1     0       0       2      0    0    0      0        1        0
##   33       1     0       0       2      0    0    0      0        0        0
##   34       1     0       0       2      0    0    0      0        0        0
##   35       1     0       0       2      0    0    0      0        0        0
##   36       1     0       1       2      0    0    0      0        0        0
##   37       1     0       0       2      0    0    0      0        0        1
##   38       1     0       1       2      0    1    0      0        0        0
##   39       1     0       0       3      0    0    0      0        0        0
##   40       1     0       0       2      0    0    0      0        0        0
##   41       1     0       0       2      0    0    0      0        0        0
##   42       1     0       0       1      0    0    0      0        0        0
##   43       1     0       0       2      0    0    0      0        1        0
##   44       1     0       1       2      0    0    1      1        0        0
##   45       1     0       0       2      0    0    0      0        0        0
##   46       1     0       0       2      0    0    0      0        0        0
##   47       1     0       1       2      0    0    0      0        0        0
##   48       1     0       0       2      0    0    1      0        0        0
##   49       1     0       0       2      0    0    0      0        0        0
##   50       1     0       0       2      0    0    0      0        0        0
##   51       1     0       0       2      0    0    0      0        0        0
##   52       1     0       0       2      0    0    0      0        0        0
##   53       1     1       1       2      1    0    1      0        0        0
##   54       1     0       0       2      0    0    1      0        0        0
##   55       1     1       1       2      1    1    0      1        0        0
##   56       1     0       0       2      0    0    0      0        0        0
##   57       1     0       0       2      0    0    0      0        0        0
##   58       1     0       0       2      0    0    0      0        0        0
##   59       1     0       1       3      0    0    0      0        1        0
##   60       1     0       0       3      0    0    0      0        1        0
##   61       1     0       0       2      0    0    0      0        0        1
##   62       1     0       0       2      0    0    0      0        0        1
##   63       1     0       1       2      0    0    1      0        0        0
##   64       1     0       0       2      0    0    0      0        0        0
##   65       1     0       0       2      0    0    0      0        0        0
##   66       1     0       1       1      0    0    0      1        0        0
##   67       1     0       0       2      0    0    1      0        0        1
##   68       1     0       0       2      0    0    0      0        0        1
##   69       1     0       1       1      0    0    0      1        0        0
##   70       1     0       0       2      0    0    0      0        0        0
##   71       1     0       0       2      0    0    0      0        0        0
##   72       1     0       1       2      0    0    0      0        0        0
##   73       1     0       0       1      0    0    0      0        0        0
##   74       1     0       0       2      0    0    0      0        1        0
##   75       1     0       0       2      0    0    0      0        0        0
##   76       1     0       0       2      0    0    0      0        0        0
##   77       1     0       0       2      0    1    1      0        0        0
##   78       1     0       0       2      0    0    0      0        0        0
##   79       1     0       0       2      0    1    1      0        0        0
##   80       1     0       0       1      0    0    1      0        1        0
##   81       1     0       0       2      0    0    0      0        0        0
##   82       1     0       0       2      0    0    0      0        0        0
##   83       1     0       0       3      0    0    0      0        0        0
##   84       1     0       1       2      0    0    0      0        0        0
##   85       1     0       1       2      0    1    0      0        0        0
##   86       1     0       0       2      0    0    0      0        1        0
##   87       1     0       1       2      0    0    0      0        0        0
##   88       1     0       1       2      0    0    0      0        0        0
##   89       1     0       1       3      0    0    0      0        0        0
##   90       1     0       0       2      0    0    0      0        0        0
##   91       1     0       1       3      0    1    0      0        1        0
##   92       1     0       1       2      0    0    0      0        0        0
##   93       1     0       0       2      0    0    1      0        0        0
##   94       1     0       1       2      0    0    1      1        0        0
##   95       1     0       0       2      0    0    0      0        0        0
##   96       1     0       0       2      0    0    1      0        0        0
##   97       1     0       1       2      0    0    0      0        0        0
##   98       1     0       0       2      0    0    0      0        0        0
##   99       1     0       1       3      0    0    0      0        0        0
##   100      1     0       0       2      0    0    0      0        1        0
##   101      1     0       0       2      0    0    0      0        1        0
##      Terms
## Docs  jokowi juga partai relawan resmi subianto untuk gibran rakabuming
##   1        0    0      0       0     0        0     0      0          0
##   2        0    0      0       0     0        0     0      0          0
##   3        1    1      1       2     1        1     1      0          0
##   4        1    1      1       2     1        0     1      0          0
##   5        0    0      0       0     0        1     0      0          0
##   6        0    0      0       0     0        1     0      1          1
##   7        1    0      0       0     0        0     0      0          0
##   8        0    0      0       0     0        1     0      0          0
##   9        0    0      0       0     0        0     0      0          0
##   10       0    0      0       0     0        0     0      0          0
##   11       0    1      0       0     0        0     0      0          0
##   12       0    0      1       0     0        1     0      0          0
##   13       0    0      0       0     0        0     0      0          0
##   14       0    0      0       0     0        0     0      1          0
##   15       0    0      1       0     0        0     0      0          0
##   16       0    0      0       0     0        0     0      1          0
##   17       1    0      0       0     0        0     0      0          0
##   18       1    0      0       0     1        0     1      0          0
##   19       0    0      0       0     0        1     0      1          0
##   20       1    0      0       0     0        0     0      0          0
##   21       1    0      0       0     1        0     1      0          0
##   22       0    0      0       0     0        0     0      0          0
##   23       0    0      1       0     0        0     0      0          0
##   24       0    1      0       0     0        0     0      0          0
##   25       1    0      0       0     0        0     0      0          0
##   26       1    0      0       0     0        0     0      0          0
##   27       1    0      0       0     0        0     0      0          0
##   28       1    0      0       0     0        0     0      0          0
##   29       1    0      0       0     0        0     0      0          0
##   30       1    0      0       0     0        0     0      0          0
##   31       0    0      0       0     0        0     0      0          0
##   32       1    0      0       0     0        0     1      0          0
##   33       0    1      0       0     0        1     0      0          0
##   34       0    0      1       0     0        0     0      0          0
##   35       0    0      2       0     0        0     0      0          0
##   36       0    0      0       0     0        0     0      0          0
##   37       0    0      0       0     0        0     0      0          0
##   38       0    0      0       0     0        0     0      1          0
##   39       1    0      0       0     1        0     0      0          0
##   40       1    0      0       0     1        0     1      0          0
##   41       0    0      0       0     0        0     0      0          0
##   42       0    0      0       0     0        0     0      1          1
##   43       0    0      0       1     0        0     0      0          0
##   44       0    0      0       0     0        1     0      1          1
##   45       0    0      1       0     0        0     0      0          0
##   46       0    0      0       0     0        0     0      0          0
##   47       0    0      0       0     0        0     0      0          0
##   48       0    0      0       0     0        0     0      0          0
##   49       0    0      1       0     0        0     0      0          0
##   50       1    0      0       0     0        1     0      0          0
##   51       0    0      0       0     0        0     0      0          0
##   52       0    0      0       0     1        0     0      0          0
##   53       0    1      0       0     0        1     0      0          0
##   54       0    0      0       0     0        0     0      1          0
##   55       0    0      0       0     0        0     0      0          0
##   56       0    0      0       0     1        0     0      0          0
##   57       0    0      0       1     0        0     0      0          0
##   58       0    0      0       0     0        0     0      1          0
##   59       1    0      0       0     1        0     1      0          0
##   60       1    0      0       0     0        0     0      0          0
##   61       0    0      2       0     0        1     0      0          0
##   62       0    0      0       0     0        0     0      0          0
##   63       0    0      0       0     0        0     0      1          0
##   64       0    0      1       0     0        0     0      0          0
##   65       1    0      0       0     0        0     0      0          0
##   66       0    0      0       0     0        0     0      0          0
##   67       0    0      0       0     0        0     0      0          0
##   68       0    0      0       0     1        0     0      0          0
##   69       0    0      0       0     0        0     0      0          0
##   70       0    0      1       0     0        0     0      0          0
##   71       1    0      0       0     0        0     0      0          0
##   72       0    0      0       0     0        0     0      0          0
##   73       0    0      0       0     0        0     0      1          1
##   74       1    0      0       0     0        0     0      0          0
##   75       0    0      1       0     0        0     0      0          0
##   76       0    0      0       0     1        0     0      0          0
##   77       0    0      0       0     0        0     0      1          0
##   78       0    0      1       0     0        0     0      0          0
##   79       0    0      0       0     0        0     0      1          0
##   80       0    0      0       0     0        0     1      1          0
##   81       0    0      1       0     0        0     0      0          0
##   82       0    0      0       1     0        1     0      0          0
##   83       1    0      0       0     0        0     0      0          0
##   84       0    0      0       0     0        0     0      0          0
##   85       0    0      0       0     0        0     0      1          1
##   86       1    0      0       0     0        0     0      0          0
##   87       0    0      0       0     0        0     0      0          0
##   88       0    0      0       0     0        0     0      0          0
##   89       1    0      0       0     1        0     0      0          0
##   90       0    0      1       0     0        0     0      0          0
##   91       0    0      0       0     1        0     0      0          0
##   92       0    0      0       0     0        0     0      0          0
##   93       0    0      0       0     0        0     0      0          0
##   94       0    0      0       0     0        0     0      1          1
##   95       0    0      0       0     0        0     0      1          0
##   96       0    0      0       0     0        0     0      1          0
##   97       0    0      0       1     0        0     0      0          0
##   98       1    0      0       0     0        0     0      0          0
##   99       1    0      0       0     1        0     1      0          0
##   100      1    0      0       0     0        0     1      0          0
##   101      0    0      0       1     0        1     0      0          0
##      Terms
## Docs  melanjutkan programprogram projo menang golkar pan fahri hamzah program
##   1             0              0     0      0      0   0     0      0       0
##   2             0              0     0      0      0   0     0      0       0
##   3             0              0     0      0      0   0     0      0       0
##   4             0              0     0      0      0   0     0      0       0
##   5             0              0     0      0      0   0     0      0       0
##   6             0              0     0      0      0   0     0      0       0
##   7             1              1     1      0      0   0     0      0       0
##   8             0              0     0      0      0   0     0      0       0
##   9             0              0     0      0      0   0     0      0       0
##   10            0              0     0      0      0   0     0      0       0
##   11            0              0     0      1      0   0     0      0       0
##   12            0              0     0      0      1   1     0      0       0
##   13            0              0     0      0      0   0     0      0       0
##   14            0              0     0      0      0   0     1      1       0
##   15            0              0     0      0      1   1     0      0       0
##   16            0              0     0      0      0   0     1      1       0
##   17            0              0     1      0      0   0     0      0       1
##   18            1              0     1      0      0   0     0      0       1
##   19            0              0     0      0      0   0     1      1       0
##   20            0              1     0      0      0   0     0      0       0
##   21            0              0     1      0      0   0     0      0       1
##   22            0              0     0      0      1   1     0      0       0
##   23            0              0     0      0      0   0     0      0       0
##   24            0              0     0      0      0   0     0      0       0
##   25            0              1     1      0      0   0     0      0       0
##   26            1              1     1      0      0   0     0      0       0
##   27            1              1     1      0      0   0     0      0       0
##   28            0              0     1      0      0   0     0      0       1
##   29            1              0     0      0      0   0     0      0       0
##   30            0              0     1      0      0   0     0      0       1
##   31            0              0     0      0      0   0     1      1       0
##   32            1              0     1      0      0   0     0      0       0
##   33            0              0     0      0      0   0     0      0       0
##   34            0              0     1      0      0   0     0      0       0
##   35            0              0     0      0      0   0     1      1       0
##   36            0              0     1      1      0   0     0      0       0
##   37            0              0     0      0      1   1     0      0       0
##   38            0              0     0      0      0   0     1      1       0
##   39            1              1     1      0      0   0     0      0       0
##   40            1              0     1      0      0   0     0      0       1
##   41            0              0     1      0      0   0     0      0       0
##   42            0              0     0      0      0   0     1      1       0
##   43            0              0     0      0      0   0     0      0       0
##   44            0              0     0      0      0   0     1      1       0
##   45            0              0     1      0      0   0     0      0       0
##   46            0              0     1      1      0   0     0      0       0
##   47            0              0     0      0      0   0     1      1       0
##   48            0              0     1      0      0   0     0      0       0
##   49            0              0     0      0      0   0     0      0       0
##   50            0              0     0      0      0   0     0      0       1
##   51            0              0     1      0      0   0     0      0       0
##   52            0              0     1      0      0   0     0      0       0
##   53            0              0     0      0      0   0     0      0       0
##   54            0              0     0      0      0   0     0      0       0
##   55            0              0     0      0      0   0     0      0       0
##   56            0              0     1      0      0   0     0      0       0
##   57            0              0     0      0      0   0     0      0       0
##   58            0              0     0      0      0   0     0      0       0
##   59            0              0     1      0      0   0     0      0       1
##   60            0              1     1      0      0   0     0      0       0
##   61            0              0     0      0      0   0     0      0       0
##   62            0              0     0      0      1   1     0      0       0
##   63            0              0     0      0      0   0     1      1       0
##   64            0              0     1      0      0   0     0      0       0
##   65            0              0     0      1      0   0     0      0       1
##   66            0              0     0      0      0   0     1      1       0
##   67            0              0     0      0      1   1     0      0       0
##   68            0              0     0      0      1   1     0      0       0
##   69            0              0     0      0      0   0     1      1       0
##   70            0              0     1      0      0   0     0      0       0
##   71            0              1     0      0      0   0     0      0       0
##   72            0              0     0      0      0   0     1      1       0
##   73            0              0     0      0      0   0     1      1       0
##   74            0              0     1      0      0   0     0      0       0
##   75            0              0     1      0      0   0     0      0       0
##   76            0              0     1      0      0   0     0      0       0
##   77            0              0     0      0      0   0     0      0       0
##   78            0              0     1      0      0   0     0      0       0
##   79            0              0     0      0      0   0     1      1       0
##   80            0              0     0      0      0   0     0      0       0
##   81            0              0     1      0      0   0     0      0       0
##   82            0              0     0      1      0   0     0      0       0
##   83            0              0     1      0      0   0     0      0       1
##   84            0              0     0      0      0   0     1      1       0
##   85            0              0     0      0      0   0     1      1       0
##   86            0              0     1      0      0   0     0      0       0
##   87            0              0     1      1      0   0     0      0       0
##   88            0              0     1      1      0   0     0      0       0
##   89            0              0     1      0      0   0     0      0       1
##   90            0              0     1      0      0   0     0      0       0
##   91            0              0     1      0      0   0     0      0       0
##   92            0              0     1      1      0   0     0      0       0
##   93            0              0     1      0      0   0     0      0       0
##   94            0              0     0      0      0   0     1      1       0
##   95            0              0     0      0      0   0     0      0       0
##   96            0              0     0      0      0   0     0      0       0
##   97            0              0     1      1      0   0     0      0       0
##   98            0              0     0      0      0   0     0      0       0
##   99            0              0     1      0      0   0     0      0       1
##   100           1              0     1      0      0   0     0      0       0
##   101           0              0     0      0      0   0     0      0       0
##      Terms
## Docs  calon gelora presiden sebagai cawapres feb rakyat satu dukung
##   1       0      0        0       0        0   0      0    0      0
##   2       0      0        0       0        0   0      0    0      0
##   3       0      0        0       0        0   0      0    0      0
##   4       0      0        0       0        0   0      0    0      0
##   5       0      0        0       0        0   0      0    0      0
##   6       0      0        0       0        0   0      0    0      0
##   7       0      0        0       0        0   0      0    0      0
##   8       0      0        0       0        0   0      0    0      0
##   9       0      0        0       0        0   0      0    0      0
##   10      0      0        0       0        0   0      0    0      0
##   11      0      0        0       0        0   0      0    0      0
##   12      0      0        0       0        0   0      0    0      0
##   13      0      0        0       0        0   0      0    0      0
##   14      0      0        0       0        0   0      0    0      0
##   15      0      0        0       0        0   0      0    0      0
##   16      0      0        0       0        0   0      0    0      0
##   17      0      0        0       0        0   0      0    0      0
##   18      0      0        0       0        0   0      0    0      0
##   19      1      0        0       0        0   0      0    0      0
##   20      0      0        0       0        0   0      0    0      0
##   21      0      0        0       0        0   0      0    0      0
##   22      0      1        0       0        0   0      0    0      0
##   23      0      0        0       0        0   0      0    0      0
##   24      0      0        1       1        0   0      0    0      0
##   25      0      0        0       0        0   0      0    0      0
##   26      0      0        0       0        0   0      0    0      0
##   27      0      0        0       0        0   0      0    0      0
##   28      1      0        1       1        0   0      0    0      0
##   29      0      0        0       0        0   0      0    0      0
##   30      0      0        0       0        0   0      0    0      0
##   31      0      0        0       0        1   0      0    0      0
##   32      0      0        0       0        0   0      0    0      0
##   33      0      0        1       1        0   0      0    0      0
##   34      0      0        0       0        0   1      1    0      0
##   35      0      2        0       0        0   0      0    0      0
##   36      0      0        0       0        0   0      0    1      0
##   37      0      1        0       0        0   0      0    0      0
##   38      0      0        0       0        0   0      0    0      0
##   39      0      0        0       0        0   0      0    0      0
##   40      0      0        0       0        0   0      0    0      0
##   41      0      0        0       1        0   0      0    0      0
##   42      0      0        0       0        0   0      0    0      0
##   43      1      0        1       0        0   0      0    1      0
##   44      0      0        0       0        0   0      0    0      0
##   45      0      0        1       0        0   1      2    0      0
##   46      0      0        0       0        0   0      0    1      0
##   47      0      0        0       0        1   0      0    0      0
##   48      0      0        0       0        0   0      0    0      0
##   49      0      0        0       0        0   0      0    0      0
##   50      0      0        0       0        0   0      0    0      0
##   51      0      0        0       0        0   0      0    0      0
##   52      0      0        0       0        0   0      0    0      1
##   53      0      0        0       0        0   0      0    0      0
##   54      0      0        0       0        1   0      0    0      0
##   55      0      0        0       0        0   0      0    0      0
##   56      0      0        0       0        0   0      0    0      0
##   57      0      0        0       0        0   0      0    0      0
##   58      0      0        0       0        0   0      0    0      0
##   59      0      0        0       0        0   0      0    0      0
##   60      0      0        0       0        0   0      0    0      0
##   61      0      0        0       0        0   0      0    0      0
##   62      0      1        0       1        0   0      0    0      0
##   63      1      0        0       0        0   0      0    0      0
##   64      0      0        0       0        0   1      1    0      0
##   65      0      0        0       0        0   0      0    0      0
##   66      0      0        0       0        0   0      0    0      0
##   67      0      1        0       0        0   0      0    0      0
##   68      0      1        0       0        0   0      0    0      0
##   69      0      0        0       0        0   0      0    0      0
##   70      0      0        1       0        0   1      1    0      0
##   71      0      0        1       0        0   0      0    0      0
##   72      0      0        0       0        1   0      0    0      0
##   73      0      0        0       0        0   0      0    0      0
##   74      0      0        0       0        0   0      0    0      0
##   75      0      0        1       0        0   1      1    0      0
##   76      0      0        0       0        0   0      0    0      0
##   77      0      0        0       0        1   0      0    0      0
##   78      0      0        1       0        0   1      1    0      0
##   79      0      0        0       0        0   0      0    0      0
##   80      0      0        0       0        1   0      0    0      0
##   81      0      0        0       0        0   1      1    0      0
##   82      0      0        0       0        0   0      0    0      0
##   83      1      0        1       1        0   0      0    0      0
##   84      0      0        0       0        1   0      0    0      0
##   85      0      0        0       0        0   0      0    0      0
##   86      0      0        0       0        0   0      0    0      0
##   87      0      0        0       0        0   0      0    1      1
##   88      0      0        0       0        0   0      0    1      0
##   89      0      0        0       0        0   0      0    0      1
##   90      0      0        0       0        0   1      1    0      0
##   91      0      0        0       0        0   0      0    0      1
##   92      0      0        0       0        0   0      0    1      1
##   93      0      0        0       0        0   0      0    0      0
##   94      0      0        0       0        0   0      0    0      0
##   95      0      0        0       0        1   0      0    0      1
##   96      0      0        0       0        1   0      0    0      0
##   97      0      0        0       0        0   0      0    0      0
##   98      0      0        0       0        0   0      1    0      0
##   99      0      0        0       0        0   0      0    0      0
##   100     0      0        0       0        0   0      0    0      0
##   101     1      0        1       0        0   0      0    1      0
set.seed(122)
k<- 3
kmeansResult<-kmeans(m3, k)
round(kmeansResult$centers, digits=3)
##   dekade erick pilpres prabowo thohir  buat  jadi tandem dukungan gerindra
## 1  0.983 0.133   0.233   1.950  0.133 0.083 0.183  0.050    0.050    0.100
## 2  1.000 0.000   0.217   2.435  0.000 0.043 0.000  0.000    0.565    0.087
## 3  1.000 0.000   0.722   1.778  0.000 0.222 0.278  0.222    0.000    0.000
##   jokowi  juga partai relawan resmi subianto untuk gibran rakabuming
## 1  0.100 0.067  0.233   0.083 0.067    0.167 0.017  0.117      0.017
## 2  0.957 0.087  0.087   0.174 0.435    0.043 0.391  0.000      0.000
## 3  0.000 0.000  0.111   0.000 0.000    0.111 0.000  0.611      0.278
##   melanjutkan programprogram projo menang golkar   pan fahri hamzah program
## 1       0.017          0.033 0.350   0.15  0.117 0.117     0      0   0.033
## 2       0.348          0.261 0.913   0.00  0.000 0.000     0      0   0.435
## 3       0.000          0.000 0.000   0.00  0.000 0.000     1      1   0.000
##   calon gelora presiden sebagai cawapres   feb rakyat  satu dukung
## 1 0.033  0.083    0.150   0.067    0.083 0.133  0.167 0.117  0.067
## 2 0.087  0.000    0.087   0.087    0.000 0.000  0.000 0.000  0.087
## 3 0.111  0.111    0.000   0.000    0.222 0.000  0.000 0.000  0.000
for (i in 1:k) {
  cat(paste("cluster ", i, ": ", sep = ""))
  s <- sort(kmeansResult$centers[i, ], decreasing = T)
  cat(names(s)[1:5], "\n")
  # print the tweets of every cluster
  # print(tweets[which(kmeansResult£cluster==i)])
}
## cluster 1: prabowo dekade projo pilpres partai 
## cluster 2: prabowo dekade jokowi projo dukungan 
## cluster 3: prabowo dekade fahri hamzah pilpres