title: Multiply specific part of a data frame with two conditions r
body: <p>I have a data set that looks like this, called <code>Data</code>:</p>
  
  <pre><code>Country Region      Code Product name Year Value
  Sweden  Stockholm   123  Apple        1991 244   
  Sweden  Kirruna     123  Apple        1987 100
  Japan   Kyoto       543  Pie          1987 544
  Denmark Copenhagen  123  Apple        1998 787
  Denmark Copenhagen  123  Apple        1987 100
  Denmark Copenhagen  543  Pie          1991 320
  Denmark Copenhagen  126  Candy        1999 200
  Sweden  Gothenburg  126  Candy        2013 300
  Sweden  Gothenburg  157  Tomato       1987 150
  Sweden  Stockholm   125  Juice        1987 250
  Sweden  Kirruna     187  Banana       1998 310
  Japan   Kyoto       198  Ham          1987 157
  Japan   Kyoto       125  Juice        1987 550
  Japan   Tokyo       125  Juice        1991 100
  </code></pre>
  
  <p>What I want to do is to convert the <code>value</code> (sales) to Euro with respect to the specific <code>country</code> and <code>year</code>. For that I have a data file that I made with the exchange rates for the specific <code>country</code> and <code>year</code>(that is also adjusted to inflation):</p>
  
  <p><code>Exchange_rates &lt;- read_excel("Data/Exchange_rates.xlsx", col_types = c("numeric", "text", "numeric")) #year, country, value</code></p>
  
  <p>To get the value I need for <code>country</code> and <code>year</code> I use this code:</p>
  
  <pre><code>Convert_exchage_rate &lt;- function(Specific_Country, Specific_Year) {
      Specific_exchange_rate &lt;- subset(Exchange_rates, Country == Specific_Country)
      Specific_exchange_rate &lt;- subset(Specific_exchange_rate, Year == Specific_Year)
      Specific_exchange_rate &lt;- as.matrix(Specific_exchange_rate[3]) #gets the specific rate for the specific year
  
      Data &lt;- ??? * Specific_exchange_rate[1] #here comes my question 
  
  }
  
  Convert_exchage_rate("Sweden","1987")
  </code></pre>
  
  <p>My problem is that I do not know how to use R to multiply only the <code>value</code> only for the entries in <code>Data</code> where <code>"Country == Sweden"</code> and <code>"Year = 1987"</code> (<code>Specific_Country</code> and <code>Specific_Year</code> in the function above). I know how to multiply the how value column with <code>Data$Value &lt;- Data$Value * Specific_exchange_rate[1]</code>, but now how to it conditionally with two conditions.</p>
  
  <p>(later on I will make a loop to run my function for all years and all countries in <code>Data</code>, but I did not want to write that part of the code until I can get this to work for one specific country at one specific year)</p>