Tim89
April 5, 2021, 12:38pm
1
Hi there,
I have 10 matrize. All Matrize have 10 col represent 10 Teams and 26 rows represent years. In every field is a score for a given year and Team. Now I want to rank very Team in every row. For example 2007: Team1 = 5, Team2=2, Team3 =1
I tried follow code....
leaderboard <- function(x){
Leaderboard_Results <- matrix(nrow = 26, ncol = 10)
for (i in c(1:26)){
Leaderboard_Results[i,] <- rank(x[i,], ties.method="average")
}
colnames(Leaderboard_Results) <- c("Team1", "Team2", "Team3", "Team4", "Team5, "Team6", "Team7", "Team8", "Team9", "Team10")
rownames(Leaderboard_Results) <- c(1993:2018)
}
Test <- leaderboard(Matrix1)
Without the function It works. Where is my mistake?
FJCC
April 5, 2021, 1:24pm
2
The main problem is that your function does not return the Leaderboard_Results matrix. Try
leaderboard <- function(x){
Leaderboard_Results <- matrix(nrow = 26, ncol = 10)
for (i in c(1:26)){
Leaderboard_Results[i,] <- rank(x[i,], ties.method="average")
}
colnames(Leaderboard_Results) <- c("Team1", "Team2", "Team3", "Team4", "Team5",
"Team6", "Team7", "Team8", "Team9", "Team10")
rownames(Leaderboard_Results) <- c(1993:2018)
Leaderboard_Results
}
There was also a missing double quote in the code you posted but I expect that was a typo.
1 Like
system
Closed
April 12, 2021, 1:25pm
3
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed. If you have a query related to it or one of the replies, start a new topic and refer back with a link.