TUGAS MANAJEMEN DATA RELASIONAL SESI UAS

Oleh Nida Khairunnissa - G1401231061

STA1261_K2_P2

Input data Persepsi Costumer dari excel ke R

library(readxl)
## Warning: package 'readxl' was built under R version 4.4.2
file_path <- "D:\\Documents\\Downloads\\Customer Perception.xlsx"
Persepsi_Costumer <- read_excel(file_path)
## New names:
## • `` -> `...4`
## • `` -> `...6`
head(Persepsi_Costumer) #menampilkan 6 data teratas tiap kategori
## # A tibble: 6 × 13
##   Product_Quality E_Commerce Technical_Support  ...4 Complaint_Resolution  ...6
##             <dbl>      <dbl>             <dbl> <dbl>                <dbl> <dbl>
## 1             8.5        3.9               2.5   5.9                  4.8   4.9
## 2             8.2        2.7               5.1   7.2                  3.4   7.9
## 3             9.2        3.4               5.6   5.6                  5.4   7.4
## 4             6.4        3.3               7     3.7                  4.7   4.7
## 5             9          3.4               5.2   4.6                  2.2   6  
## 6             6.5        2.8               3.1   4.1                  4     4.3
## # ℹ 7 more variables: Advertising <dbl>, Product <dbl>, Salesforce <dbl>,
## #   Competitive <dbl>, Warranty <dbl>, Order <dbl>, Delivery <dbl>

Meringkas data: menghitung rata-rata semua kategori dengan fungsi summarise()

library(dplyr)
## Warning: package 'dplyr' was built under R version 4.4.2
## 
## 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
rataan_data <- Persepsi_Costumer %>%
  summarise(across(everything(), ~ mean(.x, na.rm = TRUE)))
rataan_data #menampilkan rata-rata dari semua kategori
## # A tibble: 1 × 13
##   Product_Quality E_Commerce Technical_Support  ...4 Complaint_Resolution  ...6
##             <dbl>      <dbl>             <dbl> <dbl>                <dbl> <dbl>
## 1            7.81       3.67              5.36  5.44                 4.01  5.80
## # ℹ 7 more variables: Advertising <dbl>, Product <dbl>, Salesforce <dbl>,
## #   Competitive <dbl>, Warranty <dbl>, Order <dbl>, Delivery <dbl>

Mengurutkan berdasarkan peubah Product_Quality dari nilai terbesar dengan fungsi arrange()

data_terurut <- Persepsi_Costumer %>%
  arrange(desc(Product_Quality))
head(data_terurut) #menampilkan 6 data teratas yang telah diurutkan dari nilai terbesar berdasarkan peubah Product_Quality
## # A tibble: 6 × 13
##   Product_Quality E_Commerce Technical_Support  ...4 Complaint_Resolution  ...6
##             <dbl>      <dbl>             <dbl> <dbl>                <dbl> <dbl>
## 1            10          4.3               7.1   6.3                  2.9   5.4
## 2            10          4.3               5.3   3.7                  4.2   5.4
## 3             9.9        3.7               3.7   6.1                  4.2   7  
## 4             9.9        2.8               7.2   6.9                  2.6   5.8
## 5             9.9        3.7               7.5   4.7                  5.6   7  
## 6             9.9        3                 6.8   5                    5.4   5.9
## # ℹ 7 more variables: Advertising <dbl>, Product <dbl>, Salesforce <dbl>,
## #   Competitive <dbl>, Warranty <dbl>, Order <dbl>, Delivery <dbl>

Memfilter data Product_Quality dan Order berdasarkan kondisi tertentu dengan fungsi filter()

data_filter <- Persepsi_Costumer %>%
  filter(
    Product_Quality > 7.5,  # Kondisi untuk Product_Quality
    Order >= 5.5             # Kondisi untuk Order
  )
data_filter
## # A tibble: 8 × 13
##   Product_Quality E_Commerce Technical_Support  ...4 Complaint_Resolution  ...6
##             <dbl>      <dbl>             <dbl> <dbl>                <dbl> <dbl>
## 1             9.1        4.5               3.6   6.4                  5.3   5.3
## 2             7.6        3.6               3     4                    5.1   4.2
## 3             8          3.3               6.1   5.7                  5.5   4.6
## 4             8.2        3.6               3.9   6.2                  5.8   4.9
## 5             8.3        3.4               3.3   5.5                  3.1   4.6
## 6             8          3.3               3.8   5.8                  3.2   4.6
## 7             9.1        4.5               6.1   5.9                  6.3   5.3
## 8             7.6        3.6               7.6   4.6                  4.7   4.6
## # ℹ 7 more variables: Advertising <dbl>, Product <dbl>, Salesforce <dbl>,
## #   Competitive <dbl>, Warranty <dbl>, Order <dbl>, Delivery <dbl>

Menambahkan kolom baru dengan fungsi mutate()

data_baru <- Persepsi_Costumer %>%
  mutate(
    Avg_Support = (Technical_Support + Complaint_Resolution) / 2, 
    Product_Performance_Ratio = Product_Quality / Competitive
    )
head(data_baru)
## # A tibble: 6 × 15
##   Product_Quality E_Commerce Technical_Support  ...4 Complaint_Resolution  ...6
##             <dbl>      <dbl>             <dbl> <dbl>                <dbl> <dbl>
## 1             8.5        3.9               2.5   5.9                  4.8   4.9
## 2             8.2        2.7               5.1   7.2                  3.4   7.9
## 3             9.2        3.4               5.6   5.6                  5.4   7.4
## 4             6.4        3.3               7     3.7                  4.7   4.7
## 5             9          3.4               5.2   4.6                  2.2   6  
## 6             6.5        2.8               3.1   4.1                  4     4.3
## # ℹ 9 more variables: Advertising <dbl>, Product <dbl>, Salesforce <dbl>,
## #   Competitive <dbl>, Warranty <dbl>, Order <dbl>, Delivery <dbl>,
## #   Avg_Support <dbl>, Product_Performance_Ratio <dbl>

Memilih kolom-kolom tertentu menggunakan fungsi select()

data_terpilih <- Persepsi_Costumer %>%
  select(Technical_Support, Complaint_Resolution, Product_Quality, Competitive)
data_terpilih
## # A tibble: 100 × 4
##    Technical_Support Complaint_Resolution Product_Quality Competitive
##                <dbl>                <dbl>           <dbl>       <dbl>
##  1               2.5                  4.8             8.5         4.3
##  2               5.1                  3.4             8.2         4  
##  3               5.6                  5.4             9.2         4.6
##  4               7                    4.7             6.4         3.6
##  5               5.2                  2.2             9           4.5
##  6               3.1                  4               6.5         9.5
##  7               5                    2.1             6.9         2.5
##  8               3.9                  4.6             6.2         4.8
##  9               5.1                  3.7             5.8         4.4
## 10               5.1                  4.7             6.4         5.3
## # ℹ 90 more rows

Menggunakan 2 fungsi secara bersamaan: fungsi select() dan filter()

data_2 <- Persepsi_Costumer %>%
  select(Product_Quality, Order, Delivery) %>%  # Pilih kolom yang diinginkan
  filter(Product_Quality > 7.81, Order > 4.61, Delivery > 3.8)
data_2
## # A tibble: 7 × 3
##   Product_Quality Order Delivery
##             <dbl> <dbl>    <dbl>
## 1             9.1   6.1      4.4
## 2             8     6.6      4.2
## 3             8.2   6.9      4.5
## 4             8.3   5.8      3.9
## 5             8     6.6      4.2
## 6             9.9   4.9      4  
## 7             9.1   6.1      4.4