0

If we have a dataframe A which contains dates.. and we have a dataframe B which contains part of the reference dates like this:

A:
    Year      Month      Day      X
    1990      01         01      55
    1991      03         02      324
    1992      04         11      56
    1993      06         07      4
    1994      08         12      5


B:
    Year      Month      Day      Y
    1990      01         01      1
    1991      03         02      2
    1992      04         11      3

How could I add the column Y of dataframe B to the dataframe A matching the dates. Besides, the dates that are not present in B dataframe fill them with 0, like this:

A:
        Year      Month      Day      X      Y
        1990      01         01      55      1
        1991      03         02      324     2
        1992      04         11      56      3
        1993      06         07      4       0
        1994      08         12      5       0
Gregor Thomas
  • 136,190
  • 20
  • 167
  • 294
  • `merge(x = A, y = B, all.x = T)`. You can then replace `NA` with `0` in the result. – Gregor Thomas Jan 19 '18 at 15:36
  • This operation is called a "left join", you might want to read up on [different types of joins](https://stackoverflow.com/a/20298671/903061). – Gregor Thomas Jan 19 '18 at 15:37
  • Gregor, do you have any advise about how to start to solve this? https://stackoverflow.com/questions/48835464/how-to-manage-a-table-to-obtain-information-using-conditions – Felipe Rincón Feb 17 '18 at 14:14

0 Answers0