dataset EPL_20_21 contien estadisticas de jugadores de la premier league

##Name: nombre del jugador ##Club: club en el que juega ##Nationality: nacionalidad del jugador ##Position: posicion en el campo del jugador ##Age: edad del jugador ##Matches: partidos jugados ##Starts: partifos jugados desde el incio ##Mins: minutos jugados ##Goals: goles realizador por el jugador ##Assists: asistencia realizadas por el jugador ##Passes_Attempted: pases realizados ##Perc_Passes_Completed: pases completados correctamente ##Penalty_Goals: goles de penales ##Penalty_Attempted: penales lanzados ##xG ##xA ##Yellow_Cards: tarjetas amarillas ##Red_Cards: tarjetas rojas

##install.packages("readr")
library(dplyr)
## 
## Adjuntando el paquete: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(readr) #Para leer archivos .csv
statsplayers <- read_csv("EPL_20_21.csv")
## Rows: 532 Columns: 18
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (4): Name, Club, Nationality, Position
## dbl (14): Age, Matches, Starts, Mins, Goals, Assists, Passes_Attempted, Perc...
## 
## ℹ 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.
head(statsplayers,10) 
## # A tibble: 10 × 18
##    Name      Club  Nationality Position   Age Matches Starts  Mins Goals Assists
##    <chr>     <chr> <chr>       <chr>    <dbl>   <dbl>  <dbl> <dbl> <dbl>   <dbl>
##  1 Mason Mo… Chel… ENG         MF,FW       21      36     32  2890     6       5
##  2 Edouard … Chel… SEN         GK          28      31     31  2745     0       0
##  3 Timo Wer… Chel… GER         FW          24      35     29  2602     6       8
##  4 Ben Chil… Chel… ENG         DF          23      27     27  2286     3       5
##  5 Reece Ja… Chel… ENG         DF          20      32     25  2373     1       2
##  6 César Az… Chel… ESP         DF          30      26     24  2188     1       2
##  7 N'Golo K… Chel… FRA         MF          29      30     24  2146     0       2
##  8 Jorginho  Chel… ITA         MF          28      28     23  2010     7       1
##  9 Thiago S… Chel… BRA         DF          35      23     23  1935     2       0
## 10 Kurt Zou… Chel… FRA         DF          25      24     22  2029     5       0
## # ℹ 8 more variables: Passes_Attempted <dbl>, Perc_Passes_Completed <dbl>,
## #   Penalty_Goals <dbl>, Penalty_Attempted <dbl>, xG <dbl>, xA <dbl>,
## #   Yellow_Cards <dbl>, Red_Cards <dbl>
10 %>% head(statsplayers, .)
## # A tibble: 10 × 18
##    Name      Club  Nationality Position   Age Matches Starts  Mins Goals Assists
##    <chr>     <chr> <chr>       <chr>    <dbl>   <dbl>  <dbl> <dbl> <dbl>   <dbl>
##  1 Mason Mo… Chel… ENG         MF,FW       21      36     32  2890     6       5
##  2 Edouard … Chel… SEN         GK          28      31     31  2745     0       0
##  3 Timo Wer… Chel… GER         FW          24      35     29  2602     6       8
##  4 Ben Chil… Chel… ENG         DF          23      27     27  2286     3       5
##  5 Reece Ja… Chel… ENG         DF          20      32     25  2373     1       2
##  6 César Az… Chel… ESP         DF          30      26     24  2188     1       2
##  7 N'Golo K… Chel… FRA         MF          29      30     24  2146     0       2
##  8 Jorginho  Chel… ITA         MF          28      28     23  2010     7       1
##  9 Thiago S… Chel… BRA         DF          35      23     23  1935     2       0
## 10 Kurt Zou… Chel… FRA         DF          25      24     22  2029     5       0
## # ℹ 8 more variables: Passes_Attempted <dbl>, Perc_Passes_Completed <dbl>,
## #   Penalty_Goals <dbl>, Penalty_Attempted <dbl>, xG <dbl>, xA <dbl>,
## #   Yellow_Cards <dbl>, Red_Cards <dbl>
statsplayers %>%
  select(Name, Club, Position, Goals, Mins, Red_Cards)
## # A tibble: 532 × 6
##    Name              Club    Position Goals  Mins Red_Cards
##    <chr>             <chr>   <chr>    <dbl> <dbl>     <dbl>
##  1 Mason Mount       Chelsea MF,FW        6  2890         0
##  2 Edouard Mendy     Chelsea GK           0  2745         0
##  3 Timo Werner       Chelsea FW           6  2602         0
##  4 Ben Chilwell      Chelsea DF           3  2286         0
##  5 Reece James       Chelsea DF           1  2373         0
##  6 César Azpilicueta Chelsea DF           1  2188         1
##  7 N'Golo Kanté      Chelsea MF           0  2146         0
##  8 Jorginho          Chelsea MF           7  2010         0
##  9 Thiago Silva      Chelsea DF           2  1935         1
## 10 Kurt Zouma        Chelsea DF           5  2029         0
## # ℹ 522 more rows
statsplayers %>%
  select(Name:Position)
## # A tibble: 532 × 4
##    Name              Club    Nationality Position
##    <chr>             <chr>   <chr>       <chr>   
##  1 Mason Mount       Chelsea ENG         MF,FW   
##  2 Edouard Mendy     Chelsea SEN         GK      
##  3 Timo Werner       Chelsea GER         FW      
##  4 Ben Chilwell      Chelsea ENG         DF      
##  5 Reece James       Chelsea ENG         DF      
##  6 César Azpilicueta Chelsea ESP         DF      
##  7 N'Golo Kanté      Chelsea FRA         MF      
##  8 Jorginho          Chelsea ITA         MF      
##  9 Thiago Silva      Chelsea BRA         DF      
## 10 Kurt Zouma        Chelsea FRA         DF      
## # ℹ 522 more rows
statsplayers %>%
  select(-'Name', -'Position')
## # A tibble: 532 × 16
##    Club    Nationality   Age Matches Starts  Mins Goals Assists Passes_Attempted
##    <chr>   <chr>       <dbl>   <dbl>  <dbl> <dbl> <dbl>   <dbl>            <dbl>
##  1 Chelsea ENG            21      36     32  2890     6       5             1881
##  2 Chelsea SEN            28      31     31  2745     0       0             1007
##  3 Chelsea GER            24      35     29  2602     6       8              826
##  4 Chelsea ENG            23      27     27  2286     3       5             1806
##  5 Chelsea ENG            20      32     25  2373     1       2             1987
##  6 Chelsea ESP            30      26     24  2188     1       2             2015
##  7 Chelsea FRA            29      30     24  2146     0       2             1504
##  8 Chelsea ITA            28      28     23  2010     7       1             1739
##  9 Chelsea BRA            35      23     23  1935     2       0             1871
## 10 Chelsea FRA            25      24     22  2029     5       0             1720
## # ℹ 522 more rows
## # ℹ 7 more variables: Perc_Passes_Completed <dbl>, Penalty_Goals <dbl>,
## #   Penalty_Attempted <dbl>, xG <dbl>, xA <dbl>, Yellow_Cards <dbl>,
## #   Red_Cards <dbl>
statsPremierGK <- statsplayers %>%
  mutate(Position = ifelse(Position == "GK", "SI", "NO"))
head(statsPremierGK)
## # A tibble: 6 × 18
##   Name       Club  Nationality Position   Age Matches Starts  Mins Goals Assists
##   <chr>      <chr> <chr>       <chr>    <dbl>   <dbl>  <dbl> <dbl> <dbl>   <dbl>
## 1 Mason Mou… Chel… ENG         NO          21      36     32  2890     6       5
## 2 Edouard M… Chel… SEN         SI          28      31     31  2745     0       0
## 3 Timo Wern… Chel… GER         NO          24      35     29  2602     6       8
## 4 Ben Chilw… Chel… ENG         NO          23      27     27  2286     3       5
## 5 Reece Jam… Chel… ENG         NO          20      32     25  2373     1       2
## 6 César Azp… Chel… ESP         NO          30      26     24  2188     1       2
## # ℹ 8 more variables: Passes_Attempted <dbl>, Perc_Passes_Completed <dbl>,
## #   Penalty_Goals <dbl>, Penalty_Attempted <dbl>, xG <dbl>, xA <dbl>,
## #   Yellow_Cards <dbl>, Red_Cards <dbl>
statsplayers %>%
  select(Name, Club, Position, Goals, Mins) %>%
  filter(Mins >= 100, Name == 'Harry Kane' | Name == 'Mason Mount')
## # A tibble: 2 × 5
##   Name        Club              Position Goals  Mins
##   <chr>       <chr>             <chr>    <dbl> <dbl>
## 1 Mason Mount Chelsea           MF,FW        6  2890
## 2 Harry Kane  Tottenham Hotspur FW          23  3082
statsplayers %>%
  select(Goals, Name) %>%
  filter(Goals >= 10) 
## # A tibble: 27 × 2
##    Goals Name             
##    <dbl> <chr>            
##  1    10 Raheem Sterling  
##  2    13 İlkay Gündoğan   
##  3    18 Bruno Fernandes  
##  4    11 Marcus Rashford  
##  5    10 Edinson Cavani   
##  6    22 Mohamed Salah    
##  7    11 Sadio Mané       
##  8    15 Jamie Vardy      
##  9    12 Kelechi Iheanacho
## 10    10 Tomáš Souček     
## # ℹ 17 more rows
distinct <- statsplayers %>%
  select(Goals, Name) %>%
  filter(Goals >= 10) %>%
  distinct(Name)

statsplayers %>%
  filter(Goals >= 10) %>%
  group_by(Goals) %>%
  top_n(1, wt = Goals) %>%
  ungroup() %>%
  arrange(desc(Goals), Name) %>%
  head(10)
## # A tibble: 10 × 18
##    Name      Club  Nationality Position   Age Matches Starts  Mins Goals Assists
##    <chr>     <chr> <chr>       <chr>    <dbl>   <dbl>  <dbl> <dbl> <dbl>   <dbl>
##  1 Harry Ka… Tott… ENG         FW          27      35     35  3082    23      14
##  2 Mohamed … Live… EGY         FW          28      37     34  3078    22       5
##  3 Bruno Fe… Manc… POR         MF          25      37     35  3099    18      12
##  4 Patrick … Leed… ENG         FW          26      38     37  3050    17       7
##  5 Son Heun… Tott… KOR         FW          28      37     36  3114    17      10
##  6 Dominic … Ever… ENG         FW          23      33     32  2871    16       0
##  7 Jamie Va… Leic… ENG         FW          33      34     31  2840    15       9
##  8 Ollie Wa… Asto… ENG         FW          24      37     37  3328    14       5
##  9 Alexandr… Arse… FRA         FW          29      31     22  1923    13       2
## 10 İlkay Gü… Manc… GER         MF          29      28     23  2029    13       2
## # ℹ 8 more variables: Passes_Attempted <dbl>, Perc_Passes_Completed <dbl>,
## #   Penalty_Goals <dbl>, Penalty_Attempted <dbl>, xG <dbl>, xA <dbl>,
## #   Yellow_Cards <dbl>, Red_Cards <dbl>
statsplayers %>%
  select(Goals, Name)  %>%
  count(Name) %>%
  arrange(desc(n))
## # A tibble: 524 × 2
##    Name                       n
##    <chr>                  <int>
##  1 Ainsley Maitland-Niles     2
##  2 Joe Willock                2
##  3 Mathew Ryan                2
##  4 Robert Snodgrass           2
##  5 Ross Barkley               2
##  6 Ruben Loftus-Cheek         2
##  7 Takumi Minamino            2
##  8 Theo Walcott               2
##  9 Aaron Connolly             1
## 10 Aaron Cresswell            1
## # ℹ 514 more rows