title: Converting Excel functions into R
body: <p>I have two excel functions that I am trying to convert into R: </p>
  
  <pre><code>numberShares
  =IF(AND(N213="BOH",N212="BOH")=TRUE,P212,IF(AND(N213="BOH",N212="Sell")=TRUE,ROUNDDOWN(Q212/C213,0),0))
  
  marketValue
  =IF(AND(N212="BOH",N213="BOH")=TRUE,C213*P212,IF(AND(N212="Sell",N213="Sell")=TRUE,Q212,IF(AND(N212="BOH",N213="Sell")=TRUE,P212*C213,IF(AND(N212="Sell",N213="BOH")=TRUE,Q212))))
  </code></pre>
  
  <p>The cells that are referenced include:</p>
  
  <ul>
  <li>c = closing price of a stock  </li>
  <li>n = position values of either "buy or hold" or "sell" </li>
  <li>p = number of Shares </li>
  <li>q = market value, assuming $10,000 initial equity (number of shares*closing price)</li>
  </ul>
  
  <p>and the tops of the two output columns that i am trying to recreate look like this:
  <a href="http://i.imgur.com/Ew3Xm.png" rel="nofollow">output</a></p>
  
  <p>So far, in R I have constructed a dataframe with the necessary four columns:
  <a href="http://i.imgur.com/WXKPa.png" rel="nofollow">data.frame</a></p>
  
  <p>I just don't know how to write the functions that will populate the number of shares and market value columns. For loops? ifelse?</p>
  
  <p>Again, thank you!!</p>