title: Basic Market Simulator with Agent Based Modelling in base R
body: <p>I'm trying to model a basic market simulator in R
  Rules are that Buyers will meet 1 Seller per round, and will transaction if the seller they meet has the same price as them. Once they transaction, both become DoneDeal, which is to signal that they've made a deal.</p>
  <pre><code>set.seed(5)
  
  Population &lt;- 20
  Rounds &lt;- 10
  
  
  #Generate Agents#
  Agents = data.frame(agentNo = seq(Population),
                       state = rep(c(&quot;Buyer&quot;,&quot;Seller&quot;),each = Population/2),
                       Mix = (1),
                       Price = round(runif(Population, 5, 10 ))
  )
  
  Out1 &lt;- data.frame(Seller = rep( 0, Rounds),
                     Buyer = rep( 0, Rounds),
                     DoneDeal = rep ( 0, Rounds)
  )
  
  
  #Rounds#
  
  for (k in 1:Rounds){
   
    # Set up meetings #
   
    for ( i in 1:Population) {
     
      #Set how many meetings each will have ( 1 ) #
     
      Mix1 &lt;- Agents$Mix[ i ]
     
      Meet1 &lt;- Mix1
     
      #Find who they'll meet#
     
      Meet2 &lt;- sample(1:Population, Meet1, replace = FALSE, prob = Agents$Mix)
     
      for (j in 1:length(Meet2) ){
       
        Meet1a &lt;- Agents[Meet2 [j], ]
       
        if(Meet1a$state == &quot;Buyer&quot;){
          if (Agents$Price[Agents$state == &quot;Seller&quot;][i] == Agents$Price[Agents$state== &quot;Buyer&quot;][j] ){
            Agents$state[i] &lt;- &quot;DoneDeal&quot;
          }
        }
      }
    }
   
    Out1$Seller[k] &lt;- length (Agents$state [Agents$state == &quot;Seller&quot;])
    Out1$Buyer[k] &lt;- length (Agents$state [Agents$state == &quot;Buyer&quot;])
    Out1$DoneDeal[k] &lt;- length (Agents$state [Agents$state == &quot;DoneDeal&quot;])
   
  }
  </code></pre>
  <p>I'm having a hard time making it so that Buyers only meet Sellers, and only become DoneDeals if Price of Seller = Price of Buyer. Any idea on how I could make that work? And further, I'd like to record the price of each transaction, per round.</p>