vendredi 19 avril 2019

Contradicting if else statements

I have created a dataset with the current run differentials by team for the 2019-2020 MLB season. I am trying to predict the outcome (if you should place a bet, and which team you should bet on). It is a very basic function but I am having trouble with else if statements contradicting themselves.

Notice in the code below that the statement:

if(x > y)

contradicts with:

if(x > 2*y)

When I call the function with x more than double y, it still returns "BETX" rather than the desired "LOCKX"

I am going to try to do the same thing for "LOCKY", but I would love to sort out this issue first.

Thank you in advance!

 bets <- function(x, y){
  if(x > y){
    return("BETX")
  } 
  else if(x == y){
    return("NO BET")
  }
  else if(x > 2*y){
    return("LOCKX")
  }else{
    return("BETY")
  }

}
bets(cubsdiff, diamondbacksdiff) ## BET CUBS
bets(yankeesdiff, royalsdiff) ## BET YANKS

Aucun commentaire:

Enregistrer un commentaire