Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Data.Table Full Outer Join in R without key

I have a data set as follows:
dt1 =

customerid value
1356 0.26
1298 0.38

dt2 =

project_yr value
1 0.31
2 0.79

I want to merge/ join them to get the following output:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

customerid value project_yr value
1356 0.26 1 0.31
1356 0.26 2 0.79
1298 0.38 1 0.31
1298 0.38 2 0.79

Is the quickest way to replicate df1 (similar to this Repeat rows of a data.frame) and then merge the second one on?

Or is there a way to do it using the data.table merge function?

Thankyou!

>Solution :

What you are looking for is a cross join

setkey(dt1[,c(k=1,.SD)],k) [ dt2[,c(k=1,.SD)], allow.cartesian=TRUE ][,k:=NULL]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading