title: R/Python, how to populate data based on 2 conditions without using simple for loop?
body: <p>I am doing some accounting but then wonder if there is a better way to replace for loop (CPU intensive) for long list of items.</p>
  <p>Suppose we have a transaction record like this:</p>
  <p>transaction_data</p>
  <pre><code>Qty  Date_purchase  Price_purchase  Date_sale  Price_sale  
  5    01/11/2020     ???             02/11/2020 ???         
  10   03/11/2020     ???             05/11/2020 ???         
  5    03/11/2020     ???             06/11/2020 ???         
  ....
  </code></pre>
  <p>What I have to do is fill the ??? with the price according to the date in this list.</p>
  <p>price_list</p>
  <pre><code>Date        Price
  01/11/2020  10
  02/11/2020  15
  03/11/2020  17
  .... 
  </code></pre>
  <p>I have tried merge, join but got stuck at writing the code with tidyverse in R (Can switch to Python if code work faster).</p>
  <pre><code>transaction_data
  
  
  %&gt;% transaction_data$Price_purchase  &lt;- left_join(price_list, by = c('Date_purchase', 'Date')
  
  
  %&gt;% transaction_data$Price_sale  &lt;- left_join(price_list, by = c('Date_sale', 'Date') (not working)
  </code></pre>
  <p>Edit: all the solutions are all equal good, I wish I could choose all as correct answer</p>