Transpose only certain columns in data.frame
<p>Here is the <strong>data I have</strong>:</p>

<pre><code>           am   group  v1  v2  v3    v4
1  2015-10-31       A 693 803 700   17%
2  2015-10-31       B 524 859 302   77%
3  2015-10-31       C 266 675 86    7%
4  2015-10-31       D 376 455 650   65%
5  2015-11-30       A 618 715 200   38%
6  2015-11-30       B 249 965 215   54%
7  2015-11-30       C 881 106 184   24%
8  2015-11-30       D 033 047 492   46%
9  2015-12-31       A 229 994 720   19%
10 2015-12-31       B 539 543 332   57%
11 2015-12-31       C 100 078 590   24%
12 2015-12-31       D 517 413 716   57%
</code></pre>

<p><strong>Question:</strong>
How can I transpose the data such that</p>

<ol>
<li>transpose <code>v1-v4</code> and </li>
<li>make values in <code>am</code> as column variables </li>
<li><code>group</code> variable is replicated by the number of <code>v1-v4</code></li>
</ol>

<p>The result I'd like to produce:</p>

<pre><code>group metric 2015-10-31 2015-11-30 2015-12-31
    A     v1        693        618        229
    A     v2        803        715        994 
    A     v3        700        200        720
    A     v4        17%        38%        19%
    B     v1        524        249        539
    B     v2        859        965        543 
    B     v3        302        215        332
    B     v4        77%        54%        57%
    ...
</code></pre>

<p><strong>What I have tried so far:</strong></p>

<pre><code>name &lt;- mydata$am
data &lt;- as.data.frame(t(mydata[, -1]))
colnames(mydata) &lt;- name
</code></pre>

<p>This doesn't handle <code>group</code> variable the way I want.</p>

<p>Thanks for your help.</p>