title: In R, how can I add some specific columns from a dataframe to another dataframe when some values are equal in both dataframes?
body: <p>I have two datasets which have both the same row combinations Country &amp; Year and I would like to add some columns from one dataset to the other one in a way that the row combinations match.</p>
  
  <p>Dataset 1:</p>
  
  <pre><code>+----------+------+---------+---------+-----+
  | Country  | Year | exports | imports | ... |
  +----------+------+---------+---------+-----+
  | Germany  | 2000 | 0.70    | 0.40    | ... |
  | Germany  | 2001 | 0.68    | 0.41    | ... |
  | Germany  | 2002 | 0.71    | 0.48    | ... |
  | Germany  | 2003 | ...     | ...     | ... |
  | Spain    | 2000 | 0.51    | 0.56    | ... |
  | Spain    | 2001 | 0.48    | 0.50    | ... |
  | Spain    | 2002 | 0.50    | 0.53    | ... |
  | Spain    | 2003 | ...     | ...     | ... |
  | ...      | ...  | ...     | ...     | ... |
  +----------+------+---------+---------+-----+
  </code></pre>
  
  <p>Dataset 2:</p>
  
  <pre><code>+----------+-----+------+--------------+-------+-----+
  | Country  | CC  | Year | unemployment | Pop   | ... |
  +----------+-----+------+--------------+-------+-----+
  | Germany  | GER | 2000 | 0.03         | 79.50 | ... |
  | Germany  | GER | 2001 | 0.05         | 79.53 | ... |
  | Germany  | GER | 2002 | 0.04         | 79.80 | ... |
  | Germany  | GER | 2003 | ...          | ...   | ... |
  | Hungary  | HUN | 2000 | ...          | ...   | ... |
  | Hungary  | HUN | 2001 | ...          | ...   | ... |
  | Hungary  | HUN | 2002 | ...          | ...   | ... |
  | Hungary  | HUN | 2003 | ...          | ...   | ... |
  | Spain    | ESP | 2000 | 0.08         | 40.2  | ... |
  | Spain    | ESP | 2001 | 0.11         | 40.5  | ... |
  | Spain    | ESP | 2002 | 0.10         | 40.55 | ... |
  | Spain    | ESP | 2003 | ...          | ...   | ... |
  | ...      | ... | ...  | ...          | ...   | ... |
  +----------+-----+------+--------------+-------+-----+
  </code></pre>
  
  <p>I want the merged data to look like this:</p>
  
  <pre><code>
  +----------+-----+------+---------+---------+--------------+-------+-----+
  | Country  | CC  | Year | exports | imports | unemployment | Pop   | ... |
  +----------+-----+------+---------+---------+--------------+-------+-----+
  | Germany  | GER | 2000 | 0.70    | 0.40    | 0.03         | 79.50 | ... |
  | Germany  | GER | 2001 | 0.68    | 0.41    | 0.05         | 79.53 | ... |
  | Germany  | GER | 2002 | 0.71    | 0.48    | 0.04         | 79.80 | ... |
  | Germany  | GER | 2003 | ...     | ...     | ...          | ...   | ... |
  | Spain    | ESP | 2000 | 0.51    | 0.56    | 0.08         | 40.2  | ... |
  | Spain    | ESP | 2001 | 0.48    | 0.50    | 0.11         | 40.5  | ... |
  | Spain    | ESP | 2002 | 0.50    | 0.53    | 0.10         | 40.55 | ... |
  | Spain    | ESP | 2003 | ...     | ...     | ...          | ...   | ... |
  | ...      | ... | ...  | ...     | ...     | ...          | ...   | ... |
  +----------+-----+------+---------+---------+--------------+-------+-----+
  </code></pre>
  
  <p>So, the countries which are not in dataset 1 (like Hungary in this case) are not in the merged dataset and the country code is also in the new dataset. Could someone tell me how I can achieve this? I have 28 years for about 100 countries each. So using a function in which I have to specify every combination would not be handy...</p>
  
  <p>I tried to merge it with <code>merge()</code>but did not succeed since it just created hundreds of rows with the same country and year combination.</p>