Skip to content

Commit

Permalink
commit files
Browse files Browse the repository at this point in the history
  • Loading branch information
ffalves committed Aug 29, 2023
0 parents commit 637e012
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.Rproj.user
.Rhistory
.RData
.Ruserdata
52 changes: 52 additions & 0 deletions Preparing dataset and working on ordinary methods.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
### Fifa Dataset
# https://www.kaggle.com/general/307245

### Libraries that will be used (and that you should install them)
library(dplyr)

######## PART 1
### Preparing dataset to analyse

# Transforming Fifa's csv to dataframe
fifa = read.csv('players_22.csv', encoding = 'UTF-8')

# Updating the players's ages to 2023
fifa$dob_y = substr(fifa$dob, 1, 4)
fifa = fifa %>% mutate(age_2023 = 2023 - as.numeric(dob_y))

# Separating the columns that I want to use, filtering for only Brazilian ST players below 23 years old
cols = c(1, 3, 5:9, 112, 12:13, 15:18, 24, 26, 31, 28:30, 38:43, 32:33, 36:37)
fifa_br = fifa %>% filter(nationality_name == 'Brazil',
age_2023 <= 23,
grepl('ST', player_positions)) %>%
select(all_of(cols))

# As ordinary methods demands e preview ranking for each column, I reorder them all
fifa_br = fifa_br %>% arrange(age_2023, desc(height_cm), weight_kg, desc(weak_foot),
league_level, desc(skill_moves), desc(pace), desc(shooting),
desc(passing), desc(dribbling), desc(defending), desc(physic))

# Creating a matrix with only the columns that I should use in the analysis
cols = c(1, 9, 19:26)
matrix_df = fifa_br %>% select(all_of(cols))
rownames(matrix_df) = matrix_df$sofifa_id
sofifa_id = matrix_df$sofifa_id

matrix_players = as.matrix(matrix_df[, c(2:10)])

######## PART 2
### Borda Count Method

# Calculating the player's scores by column
borda = apply(matrix_players, 2, function(column) rank(-column))

# Adding up the score of each row
borda = apply(borda, 1, sum)

# Assigning the Borda's score to each player
borda_df = data.frame(cbind(sofifa_id, borda))
fifa_om = left_join(fifa_br, borda_df, by = 'sofifa_id')

### Condorcet Count Method


13 changes: 13 additions & 0 deletions ordinary_methods.Rproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Version: 1.0

RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8

RnwWeave: Sweave
LaTeX: pdfLaTeX

0 comments on commit 637e012

Please sign in to comment.