title: I want to dissociate lists in a data frame into single values to different columns in R
body: <p>I have a database that goes like that:</p>
  <pre><code>d &lt;- c(01, 02, 03, 04)
  h &lt;- c(&quot;19:00&quot;, &quot;19:00&quot;, &quot;07:00&quot;, &quot;07:00&quot;)
  p1 &lt;- c(123, 321, 123, 123)
  p2 &lt;- c(321, 345, 567, 567)
  
  df &lt;- data.frame(date = d, hours = h, person1 = p1, person2 = p2)
  </code></pre>
  <p>I used this code to associate all the characteristics of each person1 in different columns:</p>
  <p>EDITED: <code>rn = rowid(person1, date, hours)</code> is the actual code. Not <code>rn = rowid(person1)</code></p>
  <pre><code>library(dplyr)
  library(data.table)
  library(tidyr)
  
  df1 &lt;- df %&gt;% 
    mutate(rn = rowid(person1, date, hours)) %&gt;% 
    pivot_wider(names_from = rn, values_from = c(date, hours, person2),
                names_sep=&quot;&quot;)
  </code></pre>
  <p>But this code gives me this output:</p>
  <pre><code># person1    date1        hours1                            person21
  
  # 123        c(1,3,4)     c(&quot;19:00&quot;, &quot;07:00&quot;, &quot;07:00&quot;)      c(321,567,567)
  
  # 321        2            19:00                             345     
  </code></pre>
  <p>I Dont want it to repeat values like <code>07:00</code> or <code>567</code>. I want it to give me each different value in different columns, ignoring repeated values. And if possible, organized like that:</p>
  <pre><code># person1 date1  date2 date3  date4...  hours1  hours2 ... person21  person22   person23   person24
  
  # 123     01     NA    03     04        07:00   19:00      NA        321        NA         567
  
  # 321     NA     02    NA     NA        NA      19:00      NA        NA         345        NA
  </code></pre>
  <p>person21, 22, 23 and 24 being the first, second, third, fourth, and so on person of my <code>df1$person1</code>.</p>
  <p>But the ideal output for me would be something like this:</p>
  <pre><code># person1 d01  d02  d03  d04 ...  h07:00  h19:00 ... p123  p321   p345  p567
  
  # 123     1    0    1    1   ...  1       0      ... 1      0     0     1
  
  # 321     0    1    0    0   ...  0       0      ... 1      0     0     1     
  </code></pre>
  <p>How can I do this?</p>