Data frame to wide with data compression : <p>A data set similar to this...</p>

<pre><code>    ID &lt;- c(rep(10,4),rep(20,4),rep(30,4),rep(40,4),rep(50,4))
    Activity &lt;- rep(c("In","Start","Finish","Out"),5)
    Rsn &lt;- c(rep("Rsn1",4),rep("Rsn11",4),rep("Rsn111",4),rep("Rsn11",4),rep("Rsn111",4))
    Inst &lt;- seq(1,20,1)
    Loc &lt;- c(rep("Here",4),rep("There",4),rep("Anywhere",4),rep("Somewhere",4),rep("SomewhereElse",4))
    dc &lt;- data.frame(ID,Activity,Rsn,Inst,Loc)

ID  Activity  Rsn     Inst  Loc 
10  In        Rsn1    1     Here
10  Start     Rsn1    2     Here
10  Finish    Rsn1    3     Here
10  Out       Rsn1    4     Here
20  In        Rsn11   5     There
20  Start     Rsn11   6     There
20  Finish    Rsn11   7     There
20  Out       Rsn11   8     There
30  In        Rsn111  9     Anywhere
30  Start     Rsn111  10    Anywhere
30  Finish    Rsn111  11    Anywhere
30  Out       Rsn111  12    Anywhere
40  In        Rsn11   13    Somewhere
40  Start     Rsn11   14    Somewhere
40  Finish    Rsn11   15    Somewhere
40  Out       Rsn11   16    Somewhere
50  In        Rsn111  17    SomewhereElse
50  Start     Rsn111  18    SomewhereElse
50  Finish    Rsn111  19    SomewhereElse
50  Out       Rsn111  20    SomewhereElse
</code></pre>

<p>the end result that I would like to end up with is this...</p>

<pre><code>ID2 &lt;- c(10,20,30,40,50)
In2 &lt;- seq(1,20,4)
Start2 &lt;- seq(2,20,4)
Finish2 &lt;- seq(3,20,4)
Out2 &lt;- seq(4,20,4)
Rsn2 &lt;- c("Rsn1","Rsn11","Rsn111","Rsn11","Rsn111")
Loc2 &lt;- c("Here","There","Anywhere","Somewhere","SomewhereElse")
dw &lt;- data.frame(ID2, In2, Start2, Finish2, Out2, Rsn2,Loc2)

ID  In2  Start2 Finish2 Out2  Rsn2    Loc2  
10  1    2      3       4     Rsn1    Here
20  5    6      7       8     Rsn11   There
30  9    10     11      12    Rsn111  Anywhere
40  13   14     15      16    Rsn11   Somewhere
50  17   18     19      20    Rsn111  SomewhereElse
</code></pre>

<p>I have used tidyr, reshape and can't seem to get it right.</p>

<p>The data set has 816K lines and takes forever with loops and conditionals.</p>

<p>I have broken the dataset down by the locations, but it is still slow.</p>

<p>Thanks in advance.</p>
