0

Let's assume that I have two tables of the same format, which have the following form:

Player    Goals
Brian     10
Chris     12
David     3
Phil      5
Richard   7
. . . . 
. . . .

One table has the player name, and the number of goals the player scored in the FIRST HALF of the season, and another table has the player name, and the number of goals the player scored in the SECOND HALF of the season.

I would like to combine the tables together, but the problem is that some players scored in the FIRST HALF, but they didn't score any in the SECOND HALF. In that case, his name will not be in the table that represents the first half of the season. Similarly, if the player didn't score in the FIRST HALF, but he scored in the SECOND HALF, he will be in the second table but missing in the first table.

For instance, let's assume that Chris scored 12 goals in the first season but none in the second season, then in the combined table, we'll have the following:

Player    Goals(first half)    Goals(second half)
Brian        10                     10
Chris        12                     0
....
....

I could just use the for loop and compare each row and fill in 0 whenever the player is missing in one of the tables. However, I was wondering if there's an easier way of doing it in R.

Any help would be greatly appreciated.

lmo
  • 37,904
  • 9
  • 56
  • 69
user98235
  • 830
  • 1
  • 13
  • 31

0 Answers0