How to order a data.frame based on row.names in another data frame?
<p>Basically, I had an initial <code>data.frame</code> where I used participants name as <code>row.names</code>. For various reasons, I had to stack then merge the data in the long format and then based on a factor variable I selected only a proportion of that data. And then I aggregated this so I have the wide data again with participants as row.names. However, the order is not the same. so if I wanted to <code>cbind</code> the original wide data with the new data it would mess up my data as the order of <code>row.names</code> is different. I tried <code>sort()</code>, <code>order()</code>, <code>transform()</code> and read several questions, but I couldn't find a way of doing it.</p>

<pre><code>DF1
&gt;               V1           V2           V3
&gt;     AAA        24           22           37
&gt;     BBB        21           22           33
&gt;     CCC        30           32           38
&gt;     DDD        21           23           35
</code></pre>

<p>The other data frame has the same <code>dim()</code>, however different order of the row.names. </p>

<pre><code>DF2 row.names
&gt;      BBB
&gt;      CCC
&gt;      AAA
&gt;      DDD
</code></pre>

<p>I would like to sort <code>DF1</code> based of <code>rownames(DF2)</code> so that the variables stay with the rownames, so I can then <code>cbind (D1, D2)</code> and because the rownames are equal, the same variable would belong to the same participant. I might have overcomplicated it, sorry :)</p>

<p>Basically, I want to reorder the whole <code>data.frame(DF1)</code> based on rownames in <code>DF2</code>.</p>

<p>I know it's a lame question, but I couldn't find a working answer.</p>