title: How to add variable from one dataframe to another dataframe (several conditions)
body: <p>I had a read through the existing topics, but nothing I've read matched the thing I want to do.</p>
  
  <p>dataframe 1: newdata (excerpt)</p>
  
  <pre><code>country year      sector    emissions
  Austria 1990       Total    6.229223e+04
  Austria 1990   Regulated    3.826440e+04
  Austria 1990 Unregulated    2.402783e+04
  Austria 1991       Total    6.589968e+04
  Austria 1991   Regulated    3.931820e+04
  Austria 1991 Unregulated    2.658148e+04
  </code></pre>
  
  <p>dataframe 2: EUETS (excerpt)</p>
  
  <pre><code>country         year  emissions
  Austria         2005  164925659
  Belgium         2005  282762153
  Croatia         2005          0
  Cyprus          2005   16021583
  Czech Republic  2005  288986144
  Denmark         2005  171815416
  Estonia         2005   71336242
  </code></pre>
  
  <p>What I want to do:</p>
  
  <ul>
  <li>Add information from <code>EUETS$emissions</code> to a new column <code>newdata$EUETS</code></li>
  <li>this insertation should be based on country and year and be inserted in the row for this country and year where <code>newdata$sector = "regulated"</code></li>
  <li><code>newdata$sector = "unregulated"</code> and <code>newdata$sector = "Total"</code> need to receive <code>NA</code> and under no circumstances <code>0</code></li>
  <li>if there is no corresponding information in <code>EUETS$country</code> and/or <code>EUETS$year</code>, <code>NA</code> should be inserted into <code>newdata$EUETS</code></li>
  <li>if there is information in <code>EUETS$emissions</code>, but no matching year and/or country for this in <code>newdata</code>, a new row shall be created for this information filling in the values from <code>EUETS</code> as above, but inserting <code>NA</code> in the new cells for <code>newdata$emissions = Total</code> and <code>newdata$unregulated</code>.</li>
  </ul>
  
  <p>This should look like this:</p>
  
  <pre><code>country         year      sector    emissions     EUETS
  Austria         1990       Total    6.229223e+04  NA
  Austria         1990   Regulated    3.826440e+04  2516843
  Austria         1990 Unregulated    2.402783e+04  NA
  Austria         1991       Total    6.589968e+04  NA
  Austria         1991   Regulated    3.931820e+04  446656
  Austria         1991 Unregulated    2.658148e+04  NA
  Liechtenstein   2005 Total          NA            NA
  Liechtenstein   2005 Regulated      NA            654612641
  Liechtenstein   2005 Unregulated    NA            NA
  </code></pre>
  
  <p>Liechtenstein was only in <code>EUETS$country</code> and didn't exist in <code>newdata$country</code> and was consequently added to the latter dataframe.</p>
  
  <p>This may be several questions/post in one, but I hope this is appropriate to ask here. I tried myself a few things, but didn't manage especially when it comes to filling in the values into the existing columns in newdata (country and year).</p>
  
  <p>I appreciate help with any part of this task.</p>
  
  <p>Thanks so much in advance!</p>
  
  <p>Nordsee</p>