R Markdown

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:

summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00

Including Plots

You can also embed plots, for example:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.

df_customer <- read.csv("df_customer.csv")
head(df_customer)
##   X ID_Pelanggan Jenis_Kelamin Tempat_Tinggal Penghasilan Total_Belanja
## 1 1      ID00031     Laki-laki           Desa     2227350       2563031
## 2 2      ID00079     Perempuan           Kota     9047608       8369550
## 3 3      ID00051     Perempuan           Kota     9735540       8053033
## 4 4      ID00014     Laki-laki           Kota    13510126       9799876
## 5 5      ID00067     Perempuan           Desa     7773498       6982081
## 6 6      ID00042     Laki-laki           Desa     6666740       4782002
nrow(df_customer)
## [1] 300
length(unique(df_customer$ID_Pelanggan))
## [1] 94
sort(table(df_customer$ID_Pelanggan), decreasing = TRUE)[1:3]
## 
## ID00007 ID00025 ID00089 
##       9       7       7
aggregate(Penghasilan ~ Jenis_Kelamin, data = df_customer, mean)
##   Jenis_Kelamin Penghasilan
## 1     Laki-laki     8880902
## 2     Perempuan     8505199
aggregate(Total_Belanja ~ Jenis_Kelamin, data = df_customer, mean)
##   Jenis_Kelamin Total_Belanja
## 1     Laki-laki       6034728
## 2     Perempuan       7114786
aggregate(Penghasilan ~ Tempat_Tinggal, data = df_customer, mean)
##   Tempat_Tinggal Penghasilan
## 1           Desa     6249122
## 2           Kota     9878685
aggregate(Total_Belanja ~ Tempat_Tinggal, data = df_customer, mean)
##   Tempat_Tinggal Total_Belanja
## 1           Desa       5022231
## 2           Kota       7520118
df_customer[order(-df_customer$Total_Belanja), c("ID_Pelanggan", "Total_Belanja")] |> head(5)
##     ID_Pelanggan Total_Belanja
## 76       ID00034      11626302
## 175      ID00011      11527638
## 228      ID00057      11031197
## 287      ID00093      10984825
## 33       ID00007      10846012
table(df_customer$Jenis_Kelamin)
## 
## Laki-laki Perempuan 
##       121       179
df_customer$Kategori_Penghasilan <- cut(df_customer$Penghasilan,
                                        breaks = c(-Inf, 5000000, 10000000, Inf),
                                        labels = c("Rendah", "Menengah", "Tinggi"))
table(df_customer$Kategori_Penghasilan)
## 
##   Rendah Menengah   Tinggi 
##       27      175       98