title: R JSON list element extraction in a loop
body: <p>I am parsing JSON objects from <a href="http://dev.pipl.com/io-docs" rel="nofollow">pipl.com</a>.
  Specifically I am passing a CSV of contacts using lapply fromJSON under the jsonlite library to the api.  Then I want to cbind specific elements into a flat dataframe.  I have tried mapply, sapply and lapply to then rbind as below but this isn't working as I expect for any other elements than the ones below.  I have tried it individually using the 'mini.test[<a href="http://dev.pipl.com/io-docs" rel="nofollow">1</a>]$records$user_ids' syntax but the original contacts dataframe has hundreds of records so I was thinking a loop would be able to extract the elements I want.</p>
  
  <p>I am looking to find only the user names for linkedin, facebook and twitter for each user.  Thus I was thinking some sort of grepl would help me subset it.  I have that vector created and posted the code below too.</p>
  
  <p>I have read multiple r-bloggers articles on the different "apply" functions, looked at the R Cookbook pdf, and read questions on stackoverflow.  I am stumped so really appreciate any help.</p>
  
  <pre><code>library(jsonlite)
  
  #sample data
  first&lt;-c('Victor','Steve','Mary')
  last&lt;-c('Arias','Madden','Johnson')
  contacts&lt;-cbind(first,last)
  
  
  #make urls
  urls&lt;-paste('http://api.pipl.com/search/v3/json/?first_name=',contacts[,1],'%09&amp;last_name=',contacts[,2],'&amp;pretty=True&amp;key=xxxxxxx', sep='')
  
  #Parse api
  mini.test&lt;-lapply(urls,fromJSON,simplifyMatrix=TRUE,flatten=TRUE)
  
  
  #Data frame vector name
  names &lt;- do.call(rbind, lapply(mini.test, "[[", 5))
  display &lt;-do.call(rbind, lapply(names, "[[", 3))
  
  #Grepl for 3 sources
  records &lt;- lapply(mini.test, "[[", 7)
  twitter &lt;-grepl("twitter.com",records,ignore.case = TRUE)
  facebook &lt;-grepl("facebook.com",records,ignore.case = TRUE)
  linkedin &lt;-grepl("linkedin.com",records,ignore.case = TRUE)
  </code></pre>
  
  <p>I know because of pipl's response that contacts may have multiple profile user names.  For this purpose I just need it unlisted as a string not a nested list in the dataframe.  In the end I would like a flat file that looks like below.  Again, I am sincerely appreciate the help.  I have been reading about it for 3 days without much success.</p>
  
  <pre><code>twitter  &lt;- c('twitter.username1','twitter.username2','NA')
  linkedin &lt;- c('linkedin.username1','linedin.username2','linkedin.username3')
  facebook &lt;- c('fb1','fb2','fb3,fb3a')
  
  df&lt;-cbind(display,twitter,linkedin,facebook)
  </code></pre>