title: Need to vectorize solution that using nested loops (transform data frame from long to wide format)
body: <p>I have following data frame and need to do transformation from long into wide format:</p>
  
  <pre><code>symbol side price
  1      A    B     1
  2      A    S     2
  3      B    B     3
  4      C    B     4
  5      B    S     5
  </code></pre>
  
  <p><strong>Explanation:</strong> for every symbol must exists two lines with side B and side S. Need to find these lines and transform them into wide format: </p>
  
  <p><code>[symbol, first-comed side (B or S), price of side B, price of side S]</code> </p>
  
  <p>If one line exists but another is missing, then put NA value to appropriate price value. For example if line with side B exists, but with side S is missing, then put NA to price of side S.</p>
  
  <p>Output results must be following:</p>
  
  <pre><code>  symbol side price_B price_S
  1      A    B      1      2
  2      B    B      3      5
  3      C    B      4     NA
  </code></pre>
  
  <p>For symbols A and B we have lines with sides A and B so we transform them without NA's. Side B was first in order then we put only B side to "side" column. For symbol C we have only side B but not side S so we put NA value to the "price_S" column.</p>
  
  <p>How to vectorize it?</p>