I have a question about merging two datasets in R with conditions.
The first dataset shows which airport runway (Runway) was used on which date and whether a plane arrived or departed from that runway (A/D).
Dataset 1:
Date      Runway   Arrival/Departure
01-01-08    89      A
01-01-08    120     A
01-01-08    97      D
01-01-09    89      A
01-02-09    92      D
01-02-10    89      A
The second dataset describes the number of complaints per runway and per arrival/departure. For instance, the complaints for the second dataset belong to runway 89 and arrival (A) (though this is not mentioned in the second dataset itself as you can see).
Dataset 2:
Date       Complaints
01-01-08    12
01-01-09    15
01-02-10    53
Now I want to add the second data set to the first one, again based on date. Moreover, I want the values of the complaints of dataset 2 to be linked with Runway 89 and arrival of dataset 1. The complaints for the other runways and arrival/ departure will thus become NA.
This is an example of the final dataset that I want to create:
Date       Runway   A/D     Complaints
01-01-08    89      A       12
01-01-08    120     A       NA
01-01-08    97      D       NA
01-01-09    89      A       15
01-02-09    92      D       NA
01-02-10    89      A       53
I thought that this would work with an if statement: if runway 89 and arrival, merge dataset based on date. But I have not obtained the desired result yet and I have no idea how to proceed. Simply merging also did not work, for that will give give complaints for all the runways, but I only want it linked with runway 89 and arrival.
If anyone can help me out, I would really appreciate it!
 
     
    