dimanche 10 janvier 2021

Greater than if_else returning wrong answer in R data frame

I am finding a very odd issue in with my R data frame. In short, I have a formula that is supposed to compare two scores within a row and then place the winner in a column:

scores$Winner <- 
  ifelse(scores$Away_Score > scores$Home_Score, scores$Away_Team, scores$Home_Team)

This seems to work for the most part, but there is one row where the lower score, not higher score, is being reported as the winner. I have a screenshot below. The winning score is above 100 and it's the only score with triple digits, so I do wonder if that somehow is impacting it. enter image description here

I haven't been able to replicate this issue outside of my actual code, so the best I can do is provide my actual code, which you can find here:

https://gist.github.com/jeffgswanson/6461f41c2ef1ca51e51aba3b377c9a1f

Thanks in advance, I'm stumped. I checked and columns are numeric. Also, I tried changing if_else to ifelse and it doesn't improve.

Aucun commentaire:

Enregistrer un commentaire