title: Set up linear programming optimization in R using LpSolve?
body: <p>I have this optimization problem where I am trying to maximize column z based on a unique value from column X, but also within a constraint that each of the unique values picked of X added up column of Y most be less than (in this example) 23.  </p>
  
  <p>For example, I have this sample data:</p>
  
  <pre><code>d=data.frame(x=c(1,1,1,2,2,2,3,3,3),y=c(9,7,5,9,7,5,9,7,5),z=c(25,20,5,20,10,5,10,5,3))
  </code></pre>
  
  <p>Which looks like this:</p>
  
  <pre><code>  X  Y  Z 
  1 1  9  25     
  2 1  7  20   
  3 1  5  5    
  4 2  9  20    
  5 2  7  10     
  6 2  5  5    
  7 3  9  10     
  8 3  7  5               
  9 3  5  5
  </code></pre>
  
  <p>The result should look like this:</p>
  
  <pre><code>  X  Y  Z 
  1 1  9  25  
  4 2  9  20     
  9 3  5  5 
  </code></pre>
  
  <p>How do I set this problem up in the lpSolve::lp function?</p>