title: Optimize value with linear (or non-linear?) constraints in R
body: <p>I am trying to pick the best possible fantasy football team given different constraints. My goal is to <em>pick the players that maximize the sum of their projected points</em>. </p>
  
  <p>The constraints are:</p>
  
  <p>1) The team must include:</p>
  
  <p>-1 QB</p>
  
  <p>-2 RBs</p>
  
  <p>-2 WRs</p>
  
  <p>-1 TE</p>
  
  <p>2) A player's risk must not exceed 6</p>
  
  <p>3) The sum of the players' costs must not exceed 300. </p>
  
  <p>How can I do this?  What is the best package/function in R to optimize these constraints?  What would the function call look like to maximize the projected points given these constraints?  FYI, I'll be searching through 100-300 players.</p>
  
  <p>Thanks in advance!  Here is a small example data set:</p>
  
  <pre><code>name &lt;- c("Aaron Rodgers","Tom Brady","Arian Foster","Ray Rice","LeSean McCoy","Calvin Johnson","Larry Fitzgerald","Wes Welker","Rob Gronkowski","Jimmy Graham")
  
  pos &lt;- c("QB","QB","RB","RB","RB","WR","WR","WR","TE","TE")
  
  pts &lt;- c(167, 136, 195, 174, 144, 135, 89, 81, 114, 111) 
  
  risk &lt;- c(2.9, 3.4, 0.7, 1.1, 3.5, 5.0, 6.7, 4.7, 3.7, 8.8) 
  
  cost &lt;- c(60, 47, 63, 62, 40, 60, 50, 35, 40, 40) 
  
  mydata &lt;- data.frame(name, pos, pts, risk, cost) 
  </code></pre>