-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustomer_segmentation.R
More file actions
27 lines (19 loc) · 1.03 KB
/
Copy pathcustomer_segmentation.R
File metadata and controls
27 lines (19 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#Import data customer_segmentation.tsv dan simpan ke dalam variable data_customer
data_customer <- read.csv("https://storage.googleapis.com/dqlab-dataset/customer_segments.txt", sep="\t")
#Ubah data_customer menjadi Dataframe dengan as.data.frame jika belum merupakan Dataframe
if (!is.data.frame(data_customer))
data_customer <- as.data.frame(data_customer)
#Tampilkan 5 data teratas dari data_customer
head(data_customer,5)
#Tampilkan 5 data terbawah dari data_customer
tail(data_customer,5)
#Tampilkan struktur dari data_customer
str(data_customer)
#Gunakan function lapply() untuk melihat tipe data dari masing-masing kolom pada data_customer
lapply(data_customer, class)
#Rata-rata umur dari tiap jenis kelamin
aggregate(data_customer$Umur,list(data_customer$Jenis.Kelamin),mean)
#Jumlah individu untuk setiap profesi (gunakan FUN = length)
aggregate(data_customer$Profesi,list(data_customer$Profesi),length)
#Rata-rata nilai belanja setahun berdasarkan profesi
aggregate(data_customer$NilaiBelanjaSetahun,list(data_customer$Profesi),mean)