title: Follow-up: Extracting a data.frame from two lists in BASE R
body: <p>I'm following up on <a href="https://stackoverflow.com/a/67513402/7223434">this</a> answer. The output in <a href="https://stackoverflow.com/a/67513402/7223434">that answer</a> works great (see below):</p>
  <pre><code>             tlist.mpre tlist.sdpre tlist.n clist.mpre clist.sdpre clist.n
  Dlsk_Krlr.102       81.6        10.8      73       80.5        11.2      80
  Dlsk_Krlr.103       85.7        13.7      66       90.3         6.6      74
  Dlsk_Krlr.104       81.4        10.9      72       80.5        11.2      80
  Dlsk_Krlr.105       90.4         8.2      61       90.3         6.6      74
  </code></pre>
  <p>However, I want to extract and add two columns named <code>nms = c('time_wk','treats')</code> from <code>data</code> to the above output. But the new output (see end of R code below) gets scrambled when I add <code>nms</code> to it.</p>
  <p>Given my reproducible R code below is there a fix?</p>
  <pre><code>data &lt;- read.csv(&quot;https://raw.githubusercontent.com/rnorouzian/m2/main/q.csv&quot;)
  
  nms = c('time_wk','treats')
  
  m = split(data, data$study.name)
  
  (mm = m[&quot;Dlsk_Krlr&quot;])
  
  
  (input &lt;- lapply(mm, function(i) 
    rev(expand.grid(post = unique(i$post),outcome = unique(i$outcome)))))
  
  res &lt;- setNames(lapply(1:0, function(i) lapply(input, function(inp) Map(function(o, p)
    do.call(rbind, lapply(mm, function(x)
      x[x$control == i &amp; x$post == p &amp; x$outcome == o, , drop = FALSE])),
    inp$outcome, inp$post))), c(&quot;clist&quot;, &quot;tlist&quot;))
  
  
  (aa = setNames(lapply(seq_along(res), function(i) Filter(NROW, res[[i]][[1]])), names(res)))
  
  
  b &lt;- lapply(aa, function(x)  {
    y &lt;- do.call(rbind,  x);
    y[order(y$group), c(&quot;mpre&quot;, &quot;sdpre&quot;, &quot;n&quot;, nms)] }) ## I'm adding `nms` HERE but that scrambles the output below
  
  cc = do.call(cbind,rev(b))
  cc_1 = cc[!duplicated(cc),]
  names(cc_1)[1:6] = c('mT','sdT','nT','mC','sdC','nC')
  
  ### NEW SCRAMBLED OUTPUT AFTER ADDING `nms`:
  #                mT  sdT nT mC sdC   nC clist.sdpre clist.n clist.time_wk clist.treats
  #Dlsk_Krlr.102 81.6 10.8 73  1   2 80.5        11.2      80             1            2
  #Dlsk_Krlr.103 85.7 13.7 66  1   2 90.3         6.6      74             1            2
  #Dlsk_Krlr.104 81.4 10.9 72  1   2 80.5        11.2      80             1            2
  #Dlsk_Krlr.105 90.4  8.2 61  1   2 90.3         6.6      74             1            2
  </code></pre>