Skip to content

Instantly share code, notes, and snippets.

@mattsedlar
Created September 14, 2016 18:41
Show Gist options
  • Save mattsedlar/19f58a00be61cf777c5758d27f965664 to your computer and use it in GitHub Desktop.
Save mattsedlar/19f58a00be61cf777c5758d27f965664 to your computer and use it in GitHub Desktop.
# script detailing process for weighted scores in Runner's World dataset
# reading in the csv containing the table
dat = read.csv("data/runners-world-data.csv")
# remove the ranking column since rows are id'd 1:x
dat = dat[,2:7]
# weights provided by Runner's World
weights = c(.4,.2,.2,.1,.1)
# empty vector
weighted.total = c()
# for loop to calculate the weighted average for each row
for(i in 1:nrow(dat)) {
weighted.total = c(weighted.total, sum(dat[i,2:6] * weights))
}
# add column to dataframe
dat$Weighted.Score = weighted.total
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment