title: If else statements and assigning variables
body: <p>So I have a code that I'm working on for a game.  The game is irrelevant here, but here is the part of my code that produces the problem.  In essence, I want the function to take input of the type of soldier, then substitute in the amount of each resource that it would take to build any given amount of that soldier.  I have the latter part of the function written and working just fine, but it is the variable assignment that I am having trouble with.</p>
  
  <pre><code> cost=function(troop,from,to){
      troop=c("phalanx","druidrider","pathfinder")
      if(troop=="phalanx"){
          w=100
          cl=130
          i=55
          cr=30
     } else if(troop=="druidrider"){
          w=360
          cl=330
          i=280
          cr=120
     } else if(troop=="pathfinder"){
  </code></pre>
  
  <p>And so on.  I am wondering a few things: First, is there a more efficient way to do this?  I want to be able to type in "cost(phalanx,30,50)" and it will automatically use the values I tried to assign to phalanx for the resources w,cl,i,cr, and substitute that into the rest of the equation.  It gives me an error saying that</p>
  
  <pre><code>Warning message:
  In if (troop == "phalanx") { :
   the condition has length &gt; 1 and only the first element will be used
  </code></pre>
  
  <p>What am I doing wrong?  </p>
  
  <p>Thanks!</p>