title: R Turning a list into a matrix when the list contains objects of "different size"
body: <p>I've seen a couple of questions about turning matrices into lists (not really clear why you would want that) but the reverse operation I've been unable to find. </p>
  
  <p>Basically, following</p>
  
  <pre><code># ind.dum = data frame with 29 observations and 2635 variables
  for (i in 1:ncol(ind.dum))
  tmp[[i]]&lt;-which(rollapply(ind.dum[,i],4,identical,c(1,0,0,0),by.column=T))
  </code></pre>
  
  <p>I got a list of 2635 objects, most of which contain 1 value, bust some up to 7. I'd need to convert this to a matrix with 2635 rows and as many columns as necessary to fit every value in a separate cells (with 0 values for the rest). </p>
  
  <p>I tried all the <strong>coerce</strong> measures I know (<code>as.data.frame</code>, <code>as.matrix</code> ...) and also the option to define a new matrix with the maximum dimensions but nothing works.</p>
  
  <pre><code>m&lt;-matrix(0,nrow=2635,ncol=7)
  tmp_m&lt;-structure(tmp,dim=dim(m))
  Error in structure(tmp,dim=dim(m))dims [product 18445] do not match the length of object [2635]
  </code></pre>
  
  <p>I'm sure there's a quick fix for this so I'm hoping someone can help me with it. Btw, my values in the tmp list's objects are numeric, although some are "integer(0)" , i.e. when the pattern c(1,0,0,0) was not found in the columns of the original ind.dum matrix.</p>
  
  <p>Not sure if there is a way to use <code>unlist</code> without losing the information about which values belong originally to the same row...</p>
  
  <p><strong>Desired Output</strong>
  A matrix or dataframe with 2635 rows and 7 columns and looking like this</p>
  
  <pre><code>12 0 0 0 0 0 0
  8 14 0 0 0 0 0 
  0  0 0 0 0 0 0 
  1  4 8 12 0 0 0 
  ...
  </code></pre>
  
  <p>The values basically refer to years in which a specific pattern started. I need to be able to be able to use that information to tie this problem to an earlier problem described before (see <a href="https://stackoverflow.com/questions/22543230/finding-repeat-patterns-in-columns-of-matrix-and-tie-findings-to-another-matrix">this link</a>).</p>