title: Vectorised approach to parsing column of URLs in R
body: <p>I've got a 2 column data frame that consists of user_id and the url that they entered the site on. I'm keen to parse some key data out of the URL.</p>
  
  <p>The <code>parse_url</code> function from the <code>httr</code> pacakge seems to do a nice job of extracting the key fields but I'm stuck as to how turn this into an efficient process that creates a new data frame - I know that the 'easy option' of writing a 'for loop' is not the way to go.</p>
  
  <p>I've tried a basic approach with <code>sapply</code> which <em>seems</em> to be a step in the right direction but the transformation it does in its basic form isn't what I'm looking for.</p>
  
  <p>One potential complication is that the function nests the elements of the url separated by <code>&amp;</code> as a list within a top level variable called <code>Query</code>. My simple manual example looks like this:</p>
  
  <pre><code>library(httr)
  x &lt;- parse_url("http://www.thesite.com/en/landingpage1?currency=GBP&amp;utm_term=bar&amp;creative=15895258")
  c(x$query$utm_term, x$query$creative)
  [1] "bar"    "15895258"
  </code></pre>
  
  <p>My original data frame looks like this:  </p>
  
  <pre><code>user_id | url
  =======================================
  50      | http://www.thesite.com/en/lpage1?currency=GBP&amp;utm_term=bar&amp;creative=15895258
  
  51      | http://www.thebsite.com/en/lpage2?currency=GBP&amp;utm_term=foo&amp;creative=15895852
  
  52      | http://www.thesite.com/en/lpage1?currency=USD&amp;utm_term=foobar&amp;creative=15895498
  </code></pre>
  
  <p>And the desired output looks like this:</p>
  
  <pre><code>user_id | utm_term  | creative
  -----------------------------------
  50      | bar       | 15895258
  51      | foo       | 15895852
  52      | foobar    | 15895498
  </code></pre>
  
  <p>Any help or ideas appreciated!
  Jacob</p>