Dataframe is too big for merge - is there an alternative?
<p>I  have a dataframe with the following columns: </p>

<pre><code>id condition trial   a0   a1 ... a7   b1   b2 ... b7
 1      1      1     23   56 ... 52   87   56 ... 98
 1      1      2     57   87 ... 87   55   52 ... 52
 1      1      3     23   56 ... 52   87   56 ... 98
 2      1      1     23   56 ... 82   97   56 ... 68
</code></pre>

<p>a and b are values measured at times 0, 1 ... 7. Measure a has values at 0 and b has not. </p>

<p>I want to have it in the format:</p>

<pre><code>id condition trial time measureA  measureB
 1     1      1     0       23      NA
 1     1      2     0       57      NA
 1     1      3     0       23      NA
 ...
 1     1      1     1       56      87
 1     1      2     1       87      55 
 ...
</code></pre>

<p>In other words, I have a 7 second time series for 2 measures spread over 2*7 columns, and I wanted to "collect" them in a single column. One of them also has a value at time 0. </p>

<p>This is what I have tried so far: </p>

<p>I used the function<code>gather</code> </p>

<pre><code>x = gather(x, timeA, measureA, -c(1:3, 4:11))
x = gather(x, timeB, measureB, -c(1:3, 10,11))
</code></pre>

<p>and could put the dataframe in the following format: </p>

<pre><code>id condition trial    timeA  measureA   timeB  measureB
                         0       12       1       45
                         0       52       1       85
                         1       51       2       55
                         1       45       2       92
                         2       45       3       15
                         2       52       3       54
</code></pre>

<p>I wanted to use <code>merge</code> to merge timeA and timeB, but it does not work because the data frame is too big.  </p>

<p>I used the code: </p>

<pre><code>merge(x[1:5], x[6:7], by.x="timeA", by.y = "timeB")
</code></pre>

<p>I get the error message</p>

<pre><code>Error: cannot allocate vector of size 40980.3 Gb
</code></pre>

<p>Is there any way to achieve what I want to do? </p>