compare columns

In the future, it's very helpful if you can provide a reproducible example so the data is easy for someone to copy/paste into R. I did the work this time but in the future take a look here to learn how to create a reproducible example: FAQ: How to do a minimal reproducible example ( reprex ) for beginners


  ~home_team, ~Away_team, ~winner,
  'all Stars', 'Bosses', 'Bosses',
  'Amigos', 'Champions', 'Amigos',
  'Avenger', 'Amigos', 'Amigos'
) %>%
    home_or_away=if_else(winner==home_team, "home", "away")
#> # A tibble: 3 x 4
#>   home_team Away_team winner home_or_away
#>   <chr>     <chr>     <chr>  <chr>       
#> 1 all Stars Bosses    Bosses away        
#> 2 Amigos    Champions Amigos home        
#> 3 Avenger   Amigos    Amigos away

Created on 2021-08-08 by the reprex package (v2.0.0)