I need some help creating a subset of data. I'm sure this is a simple problem but I can't figure it out. For example, in the table, I need to create a subset of the data that includes the presidential winner from each state. So for Alabama for example, I would need the line for Donald J Trump since he got the highest proportion of votes (candidate votes/ total votes). I would need to isolate the winners from every state.
State Candidate candidatevotes totalvotes
Alabama D J Trump 1318255 2123372
Alabama Clinton 729547 2123372
Alabama Gary Johnson 44467 2123372
Alabama Other 21712 2123372
However, I don't know how to isolate the winner from each state. I have tried using using
data_sub <- filename[candidatevotes/totalvotes > .5]
but I know that since there are 3rd party candidates, not every winner from each state will win with majority votes. I have attached a picture for reference. Thank you in advance!