I have the following code:
Homecoef = 0.4
#Loop to add in column for probability the home team wins
for (i in 1:nrow(NHLSince2010))
{
NHLSince2010 <- mutate(NHLSince2010, "BTProbHomeTeamWins" = (abilitiesNHL[NHLSince2010$Home,"ability"] + Homecoef) / (abilitiesNHL[NHLSince2010$Home,"ability"] + Homecoef + abilitiesNHL[NHLSince2010$Visitor,"ability"]))
#Loop to add in column for model expected winner
NHLSince2010 <- mutate(NHLSince2010, "BTProjectedWinner" = if(NHLSince2010$BTProbHomeTeamWins > 0.50) {NHLSince2010$Home} else {NHLSince2010$Visitor})
#Loop to add in column to show if the model guessed the winner correctly
NHLSince2010 <- mutate(NHLSince2010, "BTPredictionCorrect" = if(NHLSince2010$BTProjectedWinner == NHLSince2010$Winner) {"YES"} else {"NO"})
}
NHLSince2010
Within the loop, I am mutating the df with column BTProjectedWinner which uses the if else statement to fill each value. Rather than pull the appropriate value based upon the if else logic, it keeps only pulling the NHLSince2010$Home value.
Can someone help to fix this so the if statement works properly to populate the correct value in the new df column?
Aucun commentaire:
Enregistrer un commentaire