title: Joining over separate lists
body: <p>I have two separate lists, one containing the ID of individuals, the other one containing different attributes of the individuals; in this case 3 different states "a", "b" and "c". Both lists contain 4 different points in time: "p1", "p2", "p3" and "p4".</p>
  
  <pre><code>#create ID in period 1,2,3,4
  id &lt;- list(p1=sample(c(1:5)),
             p2=sample(c(1:6)),
             p3=sample(c(3:6)),
             p4=sample(c(3:8)))
  id
  $p1
  [1] 4 3 1 2 5
  
  $p2
  [1] 6 2 5 3 1 4
  
  $p3
  [1] 3 6 5 4
  
  $p4
  [1] 7 5 8 3 4 6
  
  
  #create states in period 1,2,3,4
  states &lt;- list(p1=sample(c("a","b","c"),5,replace=TRUE),
                    p2=sample(c("a","b","c"),6,replace=TRUE),
                    p3=sample(c("a","b","c"),4,replace=TRUE),
                    p4=sample(c("a","b","c"),6,replace=TRUE))
  states
  $p1
  [1] "a" "c" "a" "b" "c"
  
  $p2
  [1] "c" "c" "b" "b" "c" "a"
  
  $p3
  [1] "b" "c" "b" "a"
  
  $p4
  [1] "a" "b" "b" "b" "c" "b"
  </code></pre>
  
  <p>The ordering of the vectors is correct, i.e. whoever has position 3 in the ID vector will have position 3 in the states vector in this period. Please note that different periods both have some different individual IDs as well as a different number of observations. Now I want to efficiently match the individual IDs over the time periods 1-4 and have a look at the individual states over time. The goal is this:</p>
  
  <pre><code>ID p1 p2 p3 p4
  1  a  c  NA NA
  2  b  c  NA NA
  3  c  b  b  b
  ...
  </code></pre>
  
  <p>My first intuition would have been to create 4 data.frames and join them, however, that seems very inefficient as well as does not give me information of where to put NAs when individuals are not present in a period.
  Any help is appreciated, thank you very much.</p>