I have the dataframe below:
def<-c("BAL","DEN","DEN")
home<-c("DEN","DEN","BAL")
away<-c("BAL","BAL","DEN")
def home away
1 BAL DEN BAL
2 DEN DEN BAL
3 DEN BAL DEN
My goal is to create a new column named def2 which will include the opposite team from the one that is included in the def column. In order to find the name of that team it should check the values of home and away columns. The final dataset should be like:
def home away def2
1 BAL DEN BAL DEN
2 DEN DEN BAL BAL
3 DEN BAL DEN BAL