title: Reconstructing variables from mcmc objects
body: <p>I am using <code>rjags</code> as a sampler. The model has 3 matrices defined. The <code>coda.samples</code> function returns a list of samples. If I take the first sample list the column names look something like this:</p>
  
  <pre><code>&gt; colnames(output[[1]])
  "A[1,1]"  "A[2,1]"  "A[1,2]"  "A[2,2]" ... 
  "B[1,1]"  "B[2,1]"  "B[3,1]"  "B[4,1]" ... 
  "C[1,1]"  "C[2,1]"
  </code></pre>
  
  <p>Obviously, A, B and C are matrices in my model. I want to reconstruct them based on the mean of these samples. I can easily get the means with <code>colMeans(output[[1]])</code> but I have no idea how to easily reconstruct the matrices from this vector. </p>
  
  <p>A good way for reconstruction would be the <code>relist()</code> function. So If I had matrices A, B and C in a list <code>L = list(A=A,B=B,C=C)</code> then I could transform this list to a vector with <code>unlist()</code> and convert back with <code>relist()</code>. I am looking for something similar/readymade for mcmc objects, but without avail so far - I can't believe I am the first one needing this. Obviously, <code>relist(colMeans(output[[1]]))</code> doesn't work.</p>
  
  <p>Anyone can help me with reconstructing? </p>
  
  <p><em>Edit: note also that the <code>relist()</code> function only needs a skeleton, so extracting the skeleton from <code>colnames(output[[1]])</code> would also do the trick. Or am I complicating?</em></p>