Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You could first find all 2-way combinations, and then just combine them with the 3d value while saving them every time. This takes a lot less memory:</p> <pre><code>combn.mod &lt;- function(x,fname){ tmp &lt;- combn(x,2,simplify=F) n &lt;- length(x) for ( i in x[-c(n,n-1)]){ # Drop all combinations that contain value i id &lt;- which(!unlist(lapply(tmp,function(t) i %in% t))) tmp &lt;- tmp[id] # add i to all other combinations and write to file out &lt;- do.call(rbind,lapply(tmp,c,i)) write(t(out),file=fname,ncolumns=3,append=T,sep=",") } } combn.mod(x,"F:/Tmp/Test.txt") </code></pre> <p>This is not as general as Joshua's answer though, it is specifically for your case. I guess it is faster -again, for this particular case-, but I didn't make the comparison. Function works on my computer using little over 50 Mb (roughly estimated) when applied to your x.</p> <p>EDIT</p> <p>On a sidenote: If this is for simulation purposes, I find it hard to believe that any scientific application needs 400+ million simulation runs. You might be asking the correct answer to the wrong question here...</p> <p>PROOF OF CONCEPT :</p> <p>I changed the write line by <code>tt[[i]]&lt;-out</code>, added <code>tt &lt;- list()</code> before the loop and return(tt) after it. Then:</p> <pre><code>&gt; do.call(rbind,combn.mod(letters[1:5])) [,1] [,2] [,3] [1,] "b" "c" "a" [2,] "b" "d" "a" [3,] "b" "e" "a" [4,] "c" "d" "a" [5,] "c" "e" "a" [6,] "d" "e" "a" [7,] "c" "d" "b" [8,] "c" "e" "b" [9,] "d" "e" "b" [10,] "d" "e" "c" </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload