hauger2
hauger2

Reputation: 35

Add a variable to this table

enter image description here

I want to add a variable to the end of this dataset that returns if shooter_player_id == player_id_off_player (could be any of players 1 through 5) return player location of corresponding 1-5. I want to find the location of the shooter. Let me know if there is a better way to show the data than linking the picture.

Upvotes: 1

Views: 62

Answers (1)

Tou Mou
Tou Mou

Reputation: 1274

df %>% mutate(z = case_when(
    shooter_player_id = playerid_off_player_1  ~ AtShot_loc_x_off_player_1 ,
    shooter_player_id = playerid_off_player_2  ~ AtShot_loc_x_off_player_2  ,
    shooter_player_id = playerid_off_player_3  ~ AtShot_loc_x_off_player_3  ,
    shooter_player_id = playerid_off_player_4  ~ AtShot_loc_x_off_player_4 ,
    shooter_player_id = playerid_off_player_5  ~ AtShot_loc_x_off_player_5
  )
)

Upvotes: 1

Related Questions