This is a feature request. I'm making a record linkage routine, and would find a cartesian product function useful. In base R, this can be done using the merge function:
<div><br></div><div><div>> x = data.frame(name = c("JOE","ANN","HARRY"), age =c(20,20,30) ); </div><div>> y = data.frame(name = c("JOE","ANN","MIKE","LARRY"), age =c(20,20,30,30) ); </div>
<div>> </div><div>> merge(x,y, by.x=NULL, by.y=NULL)</div><div> name.x age.x name.y age.y</div><div>1 JOE 20 JOE 20</div><div>2 ANN 20 JOE 20</div><div>3 HARRY 30 JOE 20</div><div>
4 JOE 20 ANN 20</div><div>5 ANN 20 ANN 20</div><div>6 HARRY 30 ANN 20</div><div>7 JOE 20 MIKE 30</div><div>8 ANN 20 MIKE 30</div><div>9 HARRY 30 MIKE 30</div>
<div>10 JOE 20 LARRY 30</div><div>11 ANN 20 LARRY 30</div><div>12 HARRY 30 LARRY 30</div></div><div><br></div><div>However, in data.table this does not work:</div><div><br></div><div><div>> x = data.table(name = c("JOE","ANN","HARRY"), age =c(20,20,30) ); </div>
<div>> y = data.table(name = c("JOE","ANN","MIKE","LARRY"), age =c(20,20,30,30) ); </div><div>> merge(x,y,by.x=NULL, by.y=NULL)</div><div>Error in merge.data.table(x, y, by.x = NULL, by.y = NULL) : </div>
<div> Can not match keys in x and y to automatically determine appropriate `by` parameter. Please set `by` value explicitly.</div></div><div><br></div><div>I've gotten around this with a hack using expand.grid and several left joins, by the way.</div>
<div>
<p class="p1"><span class="s1">pairs</span> = data.table(expand.grid(<span class="s2">1</span><span class="s3">:</span>nrow(x),<span class="s2">1</span><span class="s3">:</span>nrow(y)))</p><p class="p1">....</p></div><div>
<br></div>