title: complex nested list to a clean matrix in R?
body: <p>I have struggled for two days longs to find a way to create a specific matrix from a nested list</p>
  <p>First of all, I am sorry if I don't explain my issue correctly I am one week new to StackOverflow* and R (and programming...)!</p>
  <p>I use a file that you can find there :</p>
  <ul>
  <li>original link: <a href="https://parltrack.org/dumps/ep_mep_activities.json.lz" rel="nofollow noreferrer">https://parltrack.org/dumps/ep_mep_activities.json.lz</a></li>
  <li>Uncompressed by me here: <a href="https://wetransfer.com/downloads/701b7ac5250f451c6cb26d29b41bd88020200808183632/bb08429ca5102e3dc277f2f44d08f82220200808183652/666973" rel="nofollow noreferrer">https://wetransfer.com/downloads/701b7ac5250f451c6cb26d29b41bd88020200808183632/bb08429ca5102e3dc277f2f44d08f82220200808183652/666973</a></li>
  <li>first 3 lists and last one (out of 23905) past here: <a href="https://pastebin.com/Kq7mjis5" rel="nofollow noreferrer">https://pastebin.com/Kq7mjis5</a></li>
  </ul>
  <p>With <em>rjson</em>, I have a nested list like this :
  <a href="https://i.stack.imgur.com/cFmuM.png" rel="nofollow noreferrer">Nested list of MEP Votes</a></p>
  <pre><code>List of 23905
   $ :List of 7
    ..$ ts     : chr &quot;2004-12-16T11:49:02&quot;
    ..$ url    : chr &quot;http://www.europarl.europa.eu/RegData/seance_pleniere/proces_verbal/2004/12-16/votes_nominaux/xml/P6_PV(2004)12-16(RCV)_XC.xml&quot;
    ..$ voteid : num 7829
    ..$ title  : chr &quot;Projet de budget gÃ©nÃ©ral 2005 modifiÃ© - bloc 3&quot;
    ..$ votes  :List of 3
    .. ..$ +:List of 2
    .. .. ..$ total : num 45
    .. .. ..$ groups:List of 6
    .. .. .. ..$ ALDE   :List of 1
    .. .. .. .. ..$ : Named num 4404
    .. .. .. .. .. ..- attr(*, &quot;names&quot;)= chr &quot;mepid&quot;
    .. .. .. ..$ GUE/NGL:List of 25
    .. .. .. .. ..$ : Named num 28469
    .. .. .. .. .. ..- attr(*, &quot;names&quot;)= chr &quot;mepid&quot;
    .. .. .. .. ..$ : Named num 4298
    .. .. .. .. .. ..- attr(*, &quot;names&quot;)= chr &quot;mepid&quot;
  </code></pre>
  <p>then my goal is to have something like this :
  <a href="https://i.stack.imgur.com/2z3e0.png" rel="nofollow noreferrer">final matrix</a></p>
  <p>First I would like to keep only the lists (from [[1]] to [[23905]]) containing   $vote$+$groups$Renew or $vote$-$groups$Renew or $vote$'0'$groups$Renew. The main list (the 23905) are registered votes. My work is on the Renew group so my only interest is to have a vote where the Renew groups exist to compare them with other groups.</p>
  <p>After that my goal is to create a matrix like this all the [[x]] where we can find groups$Renewexists:
  <a href="https://i.stack.imgur.com/2z3e0.png" rel="nofollow noreferrer">final matrix</a></p>
  <pre><code> V1             V2 (not mandatory)   V3[[x]]$voteid
  [mepid==666] GUE/NGL     + (mepid==[666] is found in [[1]]$vote$+$groups$GUE/NGL)              
  [mepid==777] Renew       - (mepid==[777] is found in [[1]]$vote$-$groups$GUE/NGL)             
  </code></pre>
  <p>I want to create a matrix so I can process the votes of each MEP (referenced by their MEPid). Their votes are either + (for yea), - (for nay) or 0 (for abstain). Moreover, I would like to have political groups of MEP displayed in the column next to their mepid. We can find their political group thanks to the place where their votes are stored. If the mepid is shown in the list [[x]]$vote$+$groups$GUE/NGL she or he belongs to the GUE/NGL groups.</p>
  <p>What I want to do might look like this</p>
  <pre><code># Clean the nested list
  Keep Vote[[x]] if Vote[[x]] list contain ,
  $vote$+$groups$Renew, 
  or $vote$-$groups$Renew,
  or $vote$'0'$groups$Renew
  
  # Create the matrix (or a data.frame if it is easier)
  VoteMatrix &lt;- as.matrix(
  V1 = all &quot;mepid&quot; found in the nested list
  V2 = groups (name of the list where we can find the mepid) (not mandatory)
  V3 to Vy = If.else(mepid is in [[x]]$vote$+ then “+”,
  mepid is in [[x]]$vote$- then “-“, &quot;0&quot;)
  )
  </code></pre>
  <p>Thank you in advance,</p>
  <p>*Nevertheless, I am reading this website actively since I started R!</p>