[datatable-help] Creating New Columns In A Data Frame Based on Other Variables

a_dodger artful_dodger74 at yahoo.com
Tue Apr 10 17:45:29 CEST 2018


I have a data.frame of the following:

team_id game_id current_points
1        100       10
1        100       10
1        100       10
2        100       20 
2        100       20
2        100       20
3        101       15
3        101       15
3        101       15
4        101       5
4        101       5
4        101       5

We have 2 different games in data frame and 4 separate teams. Eg. Team 1
plays Team 2 in game_id 1. What I need to do is create another 2 column with
the points of the other team in the game and the points difference between
the two teams. Example

team_id  game_id  current_points  other_team_points  points_difference
    1        100       10               20          -10
    1        100       10               20          -10 
    1        100       10               20          -10 
    2        100       20               10           10
    2        100       20               10           10
    2        100       20               10           10
    3        101       15               5            10
    3        101       15               5            10
    3        101       15               5            10 
    4        101       5                15          -10
    4        101       5                15          -10
    4        101       5                15          -10

How do I go about this in dplyr?




--
Sent from: http://r.789695.n4.nabble.com/datatable-help-f2315188.html


More information about the datatable-help mailing list