library(DT)
library(ggplot2)
library(readr)
vt <- read_csv("~/Phạm Thị Thu Thảo/vt.csv")
## Warning: One or more parsing issues, call `problems()` on your data frame for details,
## e.g.:
##   dat <- vroom(...)
##   problems(dat)
## Rows: 123657 Columns: 12
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (7): Restaurant Name, Cuisine, Place Name, City, Item Name, Best Seller,...
## dbl (5): Dining Rating, Delivery Rating, Dining Votes, Delivery Votes, Votes
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
View(vt)
head(vt)
## # A tibble: 6 × 12
##   `Restaurant Name` `Dining Rating` `Delivery Rating` `Dining Votes`
##   <chr>                       <dbl>             <dbl>          <dbl>
## 1 Doner King                    3.9               4.2             39
## 2 Doner King                    3.9               4.2             39
## 3 Doner King                    3.9               4.2             39
## 4 Doner King                    3.9               4.2             39
## 5 Doner King                    3.9               4.2             39
## 6 Doner King                    3.9               4.2             39
## # ℹ 8 more variables: `Delivery Votes` <dbl>, Cuisine <chr>,
## #   `Place Name` <chr>, City <chr>, `Item Name` <chr>, `Best Seller` <chr>,
## #   Votes <dbl>, `Prices;` <chr>
str(vt)
## spc_tbl_ [123,657 × 12] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
##  $ Restaurant Name: chr [1:123657] "Doner King" "Doner King" "Doner King" "Doner King" ...
##  $ Dining Rating  : num [1:123657] 3.9 3.9 3.9 3.9 3.9 3.9 3.9 3.9 3.9 3.9 ...
##  $ Delivery Rating: num [1:123657] 4.2 4.2 4.2 4.2 4.2 4.2 4.2 4.2 4.2 4.2 ...
##  $ Dining Votes   : num [1:123657] 39 39 39 39 39 39 39 39 39 39 ...
##  $ Delivery Votes : num [1:123657] 0 0 0 0 0 0 0 0 0 0 ...
##  $ Cuisine        : chr [1:123657] "Fast Food" "Fast Food" "Fast Food" "Fast Food" ...
##  $ Place Name     : chr [1:123657] "Malakpet" "Malakpet" "Malakpet" "Malakpet" ...
##  $ City           : chr [1:123657] "Hyderabad" "Hyderabad" "Hyderabad" "Hyderabad" ...
##  $ Item Name      : chr [1:123657] "Platter Kebab Combo" "Chicken Rumali Shawarma" "Chicken Tandoori Salad" "Chicken BBQ Salad" ...
##  $ Best Seller    : chr [1:123657] "BESTSELLER" "BESTSELLER" NA "BESTSELLER" ...
##  $ Votes          : num [1:123657] 84 45 39 43 31 48 27 59 29 31 ...
##  $ Prices;        : chr [1:123657] "249;" "129;" "189;" "189;" ...
##  - attr(*, "spec")=
##   .. cols(
##   ..   `Restaurant Name` = col_character(),
##   ..   `Dining Rating` = col_double(),
##   ..   `Delivery Rating` = col_double(),
##   ..   `Dining Votes` = col_double(),
##   ..   `Delivery Votes` = col_double(),
##   ..   Cuisine = col_character(),
##   ..   `Place Name` = col_character(),
##   ..   City = col_character(),
##   ..   `Item Name` = col_character(),
##   ..   `Best Seller` = col_character(),
##   ..   Votes = col_double(),
##   ..   `Prices;` = col_character()
##   .. )
##  - attr(*, "problems")=<externalptr>
datatable(vt)
## Warning in instance$preRenderHook(instance): It seems your data is too big for
## client-side DataTables. You may consider server-side processing:
## https://rstudio.github.io/DT/server.html
vt <- na.omit(vt)
names(vt) <- c("RE","DI","DE","DIN","DEL","CU","PL","CI","IT","BE","VO","PR")
summary(vt)
##       RE                  DI              DE             DIN     
##  Length:20020       Min.   :2.500   Min.   :3.000   Min.   :  0  
##  Class :character   1st Qu.:3.600   1st Qu.:3.800   1st Qu.: 11  
##  Mode  :character   Median :3.900   Median :4.000   Median : 93  
##                     Mean   :3.828   Mean   :3.973   Mean   :208  
##                     3rd Qu.:4.100   3rd Qu.:4.100   3rd Qu.:310  
##                     Max.   :4.800   Max.   :4.600   Max.   :997  
##       DEL              CU                 PL                 CI           
##  Min.   :  0.00   Length:20020       Length:20020       Length:20020      
##  1st Qu.:  0.00   Class :character   Class :character   Class :character  
##  Median :  0.00   Mode  :character   Mode  :character   Mode  :character  
##  Mean   : 97.02                                                           
##  3rd Qu.:  0.00                                                           
##  Max.   :983.00                                                           
##       IT                 BE                  VO               PR           
##  Length:20020       Length:20020       Min.   :   0.00   Length:20020      
##  Class :character   Class :character   1st Qu.:   6.00   Class :character  
##  Mode  :character   Mode  :character   Median :  25.00   Mode  :character  
##                                        Mean   :  82.44                     
##                                        3rd Qu.:  73.00                     
##                                        Max.   :9750.00
ava <- mean(vt$DI, na.rm = TRUE)
print(ava)
## [1] 3.827547
ava <- as.data.frame(ava)
average <- aggregate(vt$DE ~ vt$CI, data = vt , FUN = mean, na.rm = TRUE)
print(average)
##           vt$CI    vt$DE
## 1     Ahmedabad 3.910558
## 2     Banaswadi 3.800000
## 3     Bangalore 4.008130
## 4       Chennai 3.952228
## 5           Goa 4.052229
## 6     Hyderabad 4.003471
## 7        Jaipur 4.003725
## 8         Kochi 3.876220
## 9       Kolkata 3.996623
## 10      Lucknow 3.953846
## 11 Magrath Road 3.700000
## 12 Malleshwaram 4.000000
## 13       Mumbai 3.987426
## 14    New Delhi 3.957167
## 15         Pune 4.044971
## 16       Raipur 3.920694
table(average)
##               vt$DE
## vt$CI          3.7 3.8 3.87621993127148 3.91055831951354 3.92069377990431
##   Ahmedabad      0   0                0                1                0
##   Banaswadi      0   1                0                0                0
##   Bangalore      0   0                0                0                0
##   Chennai        0   0                0                0                0
##   Goa            0   0                0                0                0
##   Hyderabad      0   0                0                0                0
##   Jaipur         0   0                0                0                0
##   Kochi          0   0                1                0                0
##   Kolkata        0   0                0                0                0
##   Lucknow        0   0                0                0                0
##   Magrath Road   1   0                0                0                0
##   Malleshwaram   0   0                0                0                0
##   Mumbai         0   0                0                0                0
##   New Delhi      0   0                0                0                0
##   Pune           0   0                0                0                0
##   Raipur         0   0                0                0                1
##               vt$DE
## vt$CI          3.95222847252272 3.95384615384615 3.95716666666667
##   Ahmedabad                   0                0                0
##   Banaswadi                   0                0                0
##   Bangalore                   0                0                0
##   Chennai                     1                0                0
##   Goa                         0                0                0
##   Hyderabad                   0                0                0
##   Jaipur                      0                0                0
##   Kochi                       0                0                0
##   Kolkata                     0                0                0
##   Lucknow                     0                1                0
##   Magrath Road                0                0                0
##   Malleshwaram                0                0                0
##   Mumbai                      0                0                0
##   New Delhi                   0                0                1
##   Pune                        0                0                0
##   Raipur                      0                0                0
##               vt$DE
## vt$CI          3.98742647058824 3.99662288930582 4 4.00347135089921
##   Ahmedabad                   0                0 0                0
##   Banaswadi                   0                0 0                0
##   Bangalore                   0                0 0                0
##   Chennai                     0                0 0                0
##   Goa                         0                0 0                0
##   Hyderabad                   0                0 0                1
##   Jaipur                      0                0 0                0
##   Kochi                       0                0 0                0
##   Kolkata                     0                1 0                0
##   Lucknow                     0                0 0                0
##   Magrath Road                0                0 0                0
##   Malleshwaram                0                0 1                0
##   Mumbai                      1                0 0                0
##   New Delhi                   0                0 0                0
##   Pune                        0                0 0                0
##   Raipur                      0                0 0                0
##               vt$DE
## vt$CI          4.00372534696859 4.00812972012439 4.04497138184791
##   Ahmedabad                   0                0                0
##   Banaswadi                   0                0                0
##   Bangalore                   0                1                0
##   Chennai                     0                0                0
##   Goa                         0                0                0
##   Hyderabad                   0                0                0
##   Jaipur                      1                0                0
##   Kochi                       0                0                0
##   Kolkata                     0                0                0
##   Lucknow                     0                0                0
##   Magrath Road                0                0                0
##   Malleshwaram                0                0                0
##   Mumbai                      0                0                0
##   New Delhi                   0                0                0
##   Pune                        0                0                1
##   Raipur                      0                0                0
##               vt$DE
## vt$CI          4.05222929936306
##   Ahmedabad                   0
##   Banaswadi                   0
##   Bangalore                   0
##   Chennai                     0
##   Goa                         1
##   Hyderabad                   0
##   Jaipur                      0
##   Kochi                       0
##   Kolkata                     0
##   Lucknow                     0
##   Magrath Road                0
##   Malleshwaram                0
##   Mumbai                      0
##   New Delhi                   0
##   Pune                        0
##   Raipur                      0
d <- max(vt$CI)
print(d)
## [1] "Raipur"
arearating <- subset(average, vt$DE == d)
print(arearating)
## [1] vt$CI vt$DE
## <0 rows> (or 0-length row.names)
ggplot(vt, aes(x = CI, y = DE)) +
  geom_col() +
  xlab("Khu vực đô thị") +
  ylab("Xếp hạng giao hàng trung bình") +
  ggtitle("Biểu đồ xếp hạng giao hàng trung bình theo khu vực đô thị")