{"id":367,"date":"2013-12-23T16:06:02","date_gmt":"2013-12-23T21:06:02","guid":{"rendered":"http:\/\/blog.espol.edu.ec\/nemo\/?p=367"},"modified":"2013-12-23T16:57:45","modified_gmt":"2013-12-23T21:57:45","slug":"merge-data-a-review-of-the-differences-between-merge-inner-join-left-join-right-join-full-join-cbind-and-rbind-when-used-data-table-objects-in-r","status":"publish","type":"post","link":"https:\/\/blog.espol.edu.ec\/nemo\/2013\/12\/23\/merge-data-a-review-of-the-differences-between-merge-inner-join-left-join-right-join-full-join-cbind-and-rbind-when-used-data-table-objects-in-r\/","title":{"rendered":"Merge data - a review of the differences between: merge, inner join, left join, right join, full join, cbind and rbind when used data.table objects in R"},"content":{"rendered":"<div style=\"overflow: auto\">\n<p class=\"geshifilter\">This post is a translation from <a title=\"Unir datos \u2013 un repaso de las diferencias entre merge, inner join, left join, right join, full join, cbind y rbind cuando se usa objetos tipo data.table en R\" href=\"http:\/\/blog.espol.edu.ec\/nemo\/2013\/12\/17\/unir-datos-repaso-de-merge-join-cbind-rbind-con-objetos-tipo-data-table-en-r\/\" target=\"_blank\">\"Unir datos \u2013 un repaso de las diferencias entre merge, inner join, left join, right join, full join, cbind y rbind cuando se usa objetos tipo data.table en R<\/a>\",\u00a0in response to a request in TW, so pardon my english.<\/p>\n<p class=\"geshifilter\">This week someone\u00a0ask me how to make joins using <a title=\"data.table package on cran\" href=\"http:\/\/cran.r-project.org\/web\/packages\/data.table\/index.html\" target=\"_blank\">data.table<\/a>\u00a0objects, this person was hesitating whether to use: merge, rbind o cbind; so I've made this blog post leveraging the script that we used to explain the differences.<\/p>\n<p><span style=\"font-size: 12px;line-height: 18px\">When we want to join two datasets usually do one of this:<\/span><\/p>\n<ul>\n<li><strong>Add Rows:<\/strong> Increase the rows of a dataset under the other.<\/li>\n<li><strong>Add Columns:<\/strong> Increase the columns of a data set to another.<\/li>\n<li style=\"text-align: justify\"><strong>Join (vlookup):<\/strong>\u00a0In this case we have some columns or variables as \"key\" or \"id\", with this columns or variables the data from the first set is added to the second when the \"key\" or \"id\" in both datasets is the same. Vlookup is a MSExcels users's term but actually is a particular case of Join which is the right term for computacional people. There are different types of Join, in summary:\n<ul>\n<li><span style=\"text-decoration: underline\">Inner Join:<\/span>\u00a0Returns only the data wich has \"matched keys\" in both datasets.<\/li>\n<li><span style=\"text-decoration: underline\">Left Join:<\/span> Return all data from the left dataset and the data with matched key from the right dataset\u00a0(vlookup is a left join).<\/li>\n<li><span style=\"text-decoration: underline\">Right Join:<\/span>\u00a0Return all data from the right dataset and the data with matched key from the left dataset.<\/li>\n<li><span style=\"text-decoration: underline\">Full Join:<\/span>\u00a0Returns all data from both datasets, obviously combining the data from the matched keys<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>The data.table package is an excellent choice to perform tasks more efficiently in R, but to learn how to use it a bit of reading and patience is required, you can read <a title=\"data.table vignette\" href=\"http:\/\/cran.r-project.org\/web\/packages\/data.table\/vignettes\/datatable-intro.pdf\" target=\"_blank\">their vignettes as a good introduction<\/a>.<\/p>\n<p>To perform joins you can use the Dt [X] syntax from data.table package or use the merge command as if they were data.frame objects. Dt [X] is more efficient than merge for merge counterpart is more intuitive (at least for the average user of R). To understand a little the Dt [X] syntax\u00a0you have to know that when you write Dt [X] the software will search the keys in Dt object based on the X's key, ie, the basis for the merge is the object X<\/p>\n<p class=\"geshifilter\"><span style=\"font-size: 12px;line-height: 18px\"><span style=\"font-size: 12px;line-height: 18px\">The following script shows how to make Inner Join, Left Join (vlookup), Right Join, Full Join, add columns and rows using 3 data.table object type (note that the output starts with a # # #, as you see when used knitr)<\/span><\/span><\/p>\n<div style=\"overflow: auto\">\n<div class=\"geshifilter\">\n<pre class=\"r geshifilter-R\" style=\"font-family: monospace\"><span style=\"color: #666666;font-style: italic\"># Load package<\/span>\r\n<a href=\"http:\/\/inside-r.org\/r-doc\/base\/library\"><span style=\"color: #003399;font-weight: bold\">library<\/span><\/a><span style=\"color: #009900\">(<\/span><a href=\"http:\/\/inside-r.org\/packages\/cran\/data.table\"><span>data.table<\/span><\/a><span style=\"color: #009900\">)<\/span>\r\n\r\n<span style=\"color: #666666;font-style: italic\"># We will create three data.frames with two 'id columns': 'id1' and 'id2' \r\n# but with different columns between them, also the 'ids' for each \r\n# data.frames will have matching and different elements<\/span>\r\ndf1 <span>&lt;-<\/span> <a href=\"http:\/\/inside-r.org\/r-doc\/base\/data.frame\"><span style=\"color: #003399;font-weight: bold\">data.frame<\/span><\/a><span style=\"color: #009900\">(<\/span>id1 = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/c\"><span style=\"color: #003399;font-weight: bold\">c<\/span><\/a><span style=\"color: #009900\">(<\/span><span style=\"color: #cc66cc\">11<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #cc66cc\">12<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #cc66cc\">13<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #cc66cc\">14<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">,<\/span> id2 = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/c\"><span style=\"color: #003399;font-weight: bold\">c<\/span><\/a><span style=\"color: #009900\">(<\/span><span style=\"color: #cc66cc\">21<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #cc66cc\">22<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #cc66cc\">23<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #cc66cc\">24<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">,<\/span> c11 = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/c\"><span style=\"color: #003399;font-weight: bold\">c<\/span><\/a><span style=\"color: #009900\">(<\/span><span style=\"color: #cc66cc\">1<\/span><span style=\"color: #339933\">,<\/span> \r\n    <span style=\"color: #cc66cc\">2<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #cc66cc\">3<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #cc66cc\">4<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">,<\/span> c12 = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/c\"><span style=\"color: #003399;font-weight: bold\">c<\/span><\/a><span style=\"color: #009900\">(<\/span><span style=\"color: #0000ff\">\"a\"<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #0000ff\">\"b\"<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #0000ff\">\"c\"<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #0000ff\">\"d\"<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #009900\">)<\/span>\r\ndf2 <span>&lt;-<\/span> <a href=\"http:\/\/inside-r.org\/r-doc\/base\/data.frame\"><span style=\"color: #003399;font-weight: bold\">data.frame<\/span><\/a><span style=\"color: #009900\">(<\/span>id1 = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/c\"><span style=\"color: #003399;font-weight: bold\">c<\/span><\/a><span style=\"color: #009900\">(<\/span><span style=\"color: #cc66cc\">99<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #cc66cc\">12<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #cc66cc\">13<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #cc66cc\">14<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">,<\/span> id2 = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/c\"><span style=\"color: #003399;font-weight: bold\">c<\/span><\/a><span style=\"color: #009900\">(<\/span><span style=\"color: #cc66cc\">98<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #cc66cc\">22<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #cc66cc\">23<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #cc66cc\">24<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">,<\/span> c21 = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/c\"><span style=\"color: #003399;font-weight: bold\">c<\/span><\/a><span style=\"color: #009900\">(<\/span><span style=\"color: #cc66cc\">5<\/span><span style=\"color: #339933\">,<\/span> \r\n    <span style=\"color: #cc66cc\">6<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #cc66cc\">7<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #cc66cc\">8<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">,<\/span> c22 = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/c\"><span style=\"color: #003399;font-weight: bold\">c<\/span><\/a><span style=\"color: #009900\">(<\/span><span style=\"color: #0000ff\">\"e\"<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #0000ff\">\"f\"<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #0000ff\">\"g\"<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #0000ff\">\"h\"<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #009900\">)<\/span>\r\ndf3 <span>&lt;-<\/span> <a href=\"http:\/\/inside-r.org\/r-doc\/base\/data.frame\"><span style=\"color: #003399;font-weight: bold\">data.frame<\/span><\/a><span style=\"color: #009900\">(<\/span>id1 = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/c\"><span style=\"color: #003399;font-weight: bold\">c<\/span><\/a><span style=\"color: #009900\">(<\/span><span style=\"color: #cc66cc\">999<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #cc66cc\">9999<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #cc66cc\">13<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #cc66cc\">14<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">,<\/span> id2 = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/c\"><span style=\"color: #003399;font-weight: bold\">c<\/span><\/a><span style=\"color: #009900\">(<\/span><span style=\"color: #cc66cc\">998<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #cc66cc\">9998<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #cc66cc\">23<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #cc66cc\">24<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">,<\/span> c31 = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/c\"><span style=\"color: #003399;font-weight: bold\">c<\/span><\/a><span style=\"color: #009900\">(<\/span><span style=\"color: #cc66cc\">9<\/span><span style=\"color: #339933\">,<\/span> \r\n    <span style=\"color: #cc66cc\">10<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #cc66cc\">11<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #cc66cc\">12<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">,<\/span> c32 = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/c\"><span style=\"color: #003399;font-weight: bold\">c<\/span><\/a><span style=\"color: #009900\">(<\/span><span style=\"color: #0000ff\">\"i\"<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #0000ff\">\"j\"<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #0000ff\">\"k\"<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #0000ff\">\"l\"<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #009900\">)<\/span>\r\n\r\n<span style=\"color: #666666;font-style: italic\"># Show data.frames<\/span>\r\ndf1\r\n<span style=\"color: #666666;font-style: italic\">##   id1 id2 c11 c12<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 1  11  21   1   a<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 2  12  22   2   b<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 3  13  23   3   c<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 4  14  24   4   d<\/span>\r\ndf2\r\n<span style=\"color: #666666;font-style: italic\">##   id1 id2 c21 c22<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 1  99  98   5   e<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 2  12  22   6   f<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 3  13  23   7   g<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 4  14  24   8   h<\/span>\r\ndf3\r\n<span style=\"color: #666666;font-style: italic\">##    id1  id2 c31 c32<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 1  999  998   9   i<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 2 9999 9998  10   j<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 3   13   23  11   k<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 4   14   24  12   l<\/span>\r\n\r\n<span style=\"color: #666666;font-style: italic\"># Transform data.frame to data.table and \r\n# set 'key' as id1 e id2 columns<\/span>\r\nDt1 <span>&lt;-<\/span> <a href=\"http:\/\/inside-r.org\/packages\/cran\/data.table\"><span>data.table<\/span><\/a><span style=\"color: #009900\">(<\/span>df1<span style=\"color: #339933\">,<\/span> key = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/c\"><span style=\"color: #003399;font-weight: bold\">c<\/span><\/a><span style=\"color: #009900\">(<\/span><span style=\"color: #0000ff\">\"id1\"<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #0000ff\">\"id2\"<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #009900\">)<\/span>\r\nDt2 <span>&lt;-<\/span> <a href=\"http:\/\/inside-r.org\/packages\/cran\/data.table\"><span>data.table<\/span><\/a><span style=\"color: #009900\">(<\/span>df2<span style=\"color: #339933\">,<\/span> key = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/c\"><span style=\"color: #003399;font-weight: bold\">c<\/span><\/a><span style=\"color: #009900\">(<\/span><span style=\"color: #0000ff\">\"id1\"<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #0000ff\">\"id2\"<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #009900\">)<\/span>\r\nDt3 <span>&lt;-<\/span> <a href=\"http:\/\/inside-r.org\/packages\/cran\/data.table\"><span>data.table<\/span><\/a><span style=\"color: #009900\">(<\/span>df3<span style=\"color: #339933\">,<\/span> key = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/c\"><span style=\"color: #003399;font-weight: bold\">c<\/span><\/a><span style=\"color: #009900\">(<\/span><span style=\"color: #0000ff\">\"id1\"<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #0000ff\">\"id2\"<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #009900\">)<\/span>\r\n\r\n<span style=\"color: #666666;font-style: italic\"># *** INNER JOIN *** <\/span>\r\n<span style=\"color: #666666;font-style: italic\"># In the Inner Join we want to get the data \r\n# wich has \"matched keys\" in both datasets<\/span>\r\n\r\n<span style=\"color: #666666;font-style: italic\"># Inner join between\u00a0Dt1 y Dt2 with data.table syntax<\/span>\r\nDt1<span style=\"color: #009900\">[<\/span>Dt2<span style=\"color: #339933\">,<\/span> nomatch = <span style=\"color: #cc66cc\">0<\/span><span style=\"color: #009900\">]<\/span>\r\n<span style=\"color: #666666;font-style: italic\">##    id1 id2 c11 c12 c21 c22<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 1:  12  22   2   b   6   f<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 2:  13  23   3   c   7   g<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 3:  14  24   4   d   8   h<\/span>\r\n<span style=\"color: #666666;font-style: italic\"># Inner join between Dt1 y Dt2, using merge command<\/span>\r\n<a href=\"http:\/\/inside-r.org\/r-doc\/base\/merge\"><span style=\"color: #003399;font-weight: bold\">merge<\/span><\/a><span style=\"color: #009900\">(<\/span>x = Dt1<span style=\"color: #339933\">,<\/span> y = Dt2<span style=\"color: #009900\">)<\/span>\r\n<span style=\"color: #666666;font-style: italic\">##    id1 id2 c11 c12 c21 c22<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 1:  12  22   2   b   6   f<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 2:  13  23   3   c   7   g<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 3:  14  24   4   d   8   h<\/span>\r\n<span style=\"color: #666666;font-style: italic\"># Inner join between Dt1, Dt2 and Dt3 with data.table syntax <\/span>\r\nDt1<span style=\"color: #009900\">[<\/span>Dt2<span style=\"color: #009900\">[<\/span>Dt3<span style=\"color: #339933\">,<\/span> nomatch = <span style=\"color: #cc66cc\">0<\/span><span style=\"color: #009900\">]<\/span><span style=\"color: #339933\">,<\/span> nomatch = <span style=\"color: #cc66cc\">0<\/span><span style=\"color: #009900\">]<\/span>\r\n<span style=\"color: #666666;font-style: italic\">##    id1 id2 c11 c12 c21 c22 c31 c32<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 1:  13  23   3   c   7   g  11   k<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 2:  14  24   4   d   8   h  12   l<\/span>\r\n<span style=\"color: #666666;font-style: italic\"># Inner join between Dt1, Dt2 and Dt3 using Reduce and merge commands<\/span>\r\n<a href=\"http:\/\/inside-r.org\/r-doc\/base\/Reduce\"><span style=\"color: #003399;font-weight: bold\">Reduce<\/span><\/a><span style=\"color: #009900\">(<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/merge\"><span style=\"color: #003399;font-weight: bold\">merge<\/span><\/a><span style=\"color: #339933\">,<\/span> <a href=\"http:\/\/inside-r.org\/r-doc\/base\/list\"><span style=\"color: #003399;font-weight: bold\">list<\/span><\/a><span style=\"color: #009900\">(<\/span>Dt1<span style=\"color: #339933\">,<\/span> Dt2<span style=\"color: #339933\">,<\/span> Dt3<span style=\"color: #009900\">)<\/span><span style=\"color: #009900\">)<\/span>\r\n<span style=\"color: #666666;font-style: italic\">##    id1 id2 c11 c12 c21 c22 c31 c32<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 1:  13  23   3   c   7   g  11   k<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 2:  14  24   4   d   8   h  12   l<\/span>\r\n\r\n<span style=\"color: #666666;font-style: italic\"># *** RIGHT JOIN *** <\/span>\r\n<span style=\"color: #666666;font-style: italic\"># In the Right join we want to get all data from the \r\n# right dataset and only the rows with matched key from \r\n# the left dataset.<\/span>\r\n\r\n<span style=\"color: #666666;font-style: italic\"># Right join between Dt1 y Dt2 with data.table syntax<\/span>\r\nDt1<span style=\"color: #009900\">[<\/span>Dt2<span style=\"color: #339933\">,<\/span> nomatch = <span style=\"color: #000000;font-weight: bold\">NA<\/span><span style=\"color: #009900\">]<\/span>\r\n<span style=\"color: #666666;font-style: italic\">##    id1 id2 c11 c12 c21 c22<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 1:  12  22   2   b   6   f<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 2:  13  23   3   c   7   g<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 3:  14  24   4   d   8   h<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 4:  99  98  NA  NA   5   e<\/span>\r\n<span style=\"color: #666666;font-style: italic\"># Right join between Dt1 y Dt2, using merge command<\/span>\r\n<a href=\"http:\/\/inside-r.org\/r-doc\/base\/merge\"><span style=\"color: #003399;font-weight: bold\">merge<\/span><\/a><span style=\"color: #009900\">(<\/span>x = Dt1<span style=\"color: #339933\">,<\/span> y = Dt2<span style=\"color: #339933\">,<\/span> all.y = <span style=\"color: #000000;font-weight: bold\">TRUE<\/span><span style=\"color: #009900\">)<\/span>\r\n<span style=\"color: #666666;font-style: italic\">##    id1 id2 c11 c12 c21 c22<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 1:  12  22   2   b   6   f<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 2:  13  23   3   c   7   g<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 3:  14  24   4   d   8   h<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 4:  99  98  NA  NA   5   e<\/span>\r\n<span style=\"color: #666666;font-style: italic\"># Right join between Dt1, Dt2 and Dt3 with data.table syntax <\/span>\r\nDt1<span style=\"color: #009900\">[<\/span>Dt2<span style=\"color: #009900\">[<\/span>Dt3<span style=\"color: #339933\">,<\/span> nomatch = <span style=\"color: #000000;font-weight: bold\">NA<\/span><span style=\"color: #009900\">]<\/span><span style=\"color: #339933\">,<\/span> nomatch = <span style=\"color: #000000;font-weight: bold\">NA<\/span><span style=\"color: #009900\">]<\/span>\r\n<span style=\"color: #666666;font-style: italic\">##     id1  id2 c11 c12 c21 c22 c31 c32<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 1:   13   23   3   c   7   g  11   k<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 2:   14   24   4   d   8   h  12   l<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 3:  999  998  NA  NA  NA  NA   9   i<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 4: 9999 9998  NA  NA  NA  NA  10   j<\/span>\r\n<span style=\"color: #666666;font-style: italic\"># To make a Right Join between several data.tables we are going to \r\n# create the mergeRight function which is the \"merge command\" \r\n# setting parameter all.y = TRUE; doing this we will force to show \r\n# all data from the right dataset and only data with matched key \r\n# from the left dataset<\/span>\r\nmergeRight <span>&lt;-<\/span> <a href=\"http:\/\/inside-r.org\/r-doc\/base\/function\"><span style=\"color: #003399;font-weight: bold\">function<\/span><\/a><span style=\"color: #009900\">(<\/span>x<span style=\"color: #339933\">,<\/span> y<span style=\"color: #009900\">)<\/span> <a href=\"http:\/\/inside-r.org\/r-doc\/base\/merge\"><span style=\"color: #003399;font-weight: bold\">merge<\/span><\/a><span style=\"color: #009900\">(<\/span>x<span style=\"color: #339933\">,<\/span> y<span style=\"color: #339933\">,<\/span> all.y = <span style=\"color: #000000;font-weight: bold\">TRUE<\/span><span style=\"color: #009900\">)<\/span>\r\n<span style=\"color: #666666;font-style: italic\"># Right join between Dt1, Dt2 and Dt3 using Reduce and mergeRight function <\/span>\r\n<span style=\"color: #666666;font-style: italic\"># Noted how \"NAs\" are shown where there is no match\u00a0<\/span>\r\n<a href=\"http:\/\/inside-r.org\/r-doc\/base\/Reduce\"><span style=\"color: #003399;font-weight: bold\">Reduce<\/span><\/a><span style=\"color: #009900\">(<\/span>mergeRight<span style=\"color: #339933\">,<\/span> <a href=\"http:\/\/inside-r.org\/r-doc\/base\/list\"><span style=\"color: #003399;font-weight: bold\">list<\/span><\/a><span style=\"color: #009900\">(<\/span>Dt1<span style=\"color: #339933\">,<\/span> Dt2<span style=\"color: #339933\">,<\/span> Dt3<span style=\"color: #009900\">)<\/span><span style=\"color: #009900\">)<\/span>\r\n<span style=\"color: #666666;font-style: italic\">##     id1  id2 c11 c12 c21 c22 c31 c32<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 1:   13   23   3   c   7   g  11   k<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 2:   14   24   4   d   8   h  12   l<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 3:  999  998  NA  NA  NA  NA   9   i<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 4: 9999 9998  NA  NA  NA  NA  10   j<\/span>\r\n\r\n<span style=\"color: #666666;font-style: italic\"># *** LEFT JOIN *** <\/span>\r\n<span style=\"color: #666666;font-style: italic\"># In the Left join we want to get all data from the right dataset \r\n# and only the rows with matched key from\u00a0the right dataset<\/span>\r\n\r\n<span style=\"color: #666666;font-style: italic\"># Left join between Dt1 y Dt2 with data.table syntax <\/span>\r\n<span style=\"color: #666666;font-style: italic\"># To make a Left join in data.table we simply change the order \r\n# of the data.tables and make a right join. \r\n# You can see that the only problem with this method is the \r\n# order of the columns because the Dt2's columns are shown first<\/span>\r\nDt2<span style=\"color: #009900\">[<\/span>Dt1<span style=\"color: #339933\">,<\/span> nomatch = <span style=\"color: #000000;font-weight: bold\">NA<\/span><span style=\"color: #009900\">]<\/span>\r\n<span style=\"color: #666666;font-style: italic\">##    id1 id2 c21 c22 c11 c12<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 1:  11  21  NA  NA   1   a<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 2:  12  22   6   f   2   b<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 3:  13  23   7   g   3   c<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 4:  14  24   8   h   4   d<\/span>\r\n<span style=\"color: #666666;font-style: italic\"># Left join between Dt1 y Dt2, using merge command<\/span>\r\n<a href=\"http:\/\/inside-r.org\/r-doc\/base\/merge\"><span style=\"color: #003399;font-weight: bold\">merge<\/span><\/a><span style=\"color: #009900\">(<\/span>x = Dt1<span style=\"color: #339933\">,<\/span> y = Dt2<span style=\"color: #339933\">,<\/span> all.x = <span style=\"color: #000000;font-weight: bold\">TRUE<\/span><span style=\"color: #009900\">)<\/span>\r\n<span style=\"color: #666666;font-style: italic\">##    id1 id2 c11 c12 c21 c22<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 1:  11  21   1   a  NA  NA<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 2:  12  22   2   b   6   f<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 3:  13  23   3   c   7   g<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 4:  14  24   4   d   8   h<\/span>\r\n<span style=\"color: #666666;font-style: italic\"># Left join between Dt1, Dt2 and Dt3 with data.table syntax\r\n# idem: see the order of columns<\/span>\r\nDt3<span style=\"color: #009900\">[<\/span>Dt2<span style=\"color: #009900\">[<\/span>Dt1<span style=\"color: #339933\">,<\/span> nomatch = <span style=\"color: #000000;font-weight: bold\">NA<\/span><span style=\"color: #009900\">]<\/span><span style=\"color: #339933\">,<\/span> nomatch = <span style=\"color: #000000;font-weight: bold\">NA<\/span><span style=\"color: #009900\">]<\/span>\r\n<span style=\"color: #666666;font-style: italic\">##    id1 id2 c31 c32 c21 c22 c11 c12<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 1:  11  21  NA  NA  NA  NA   1   a<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 2:  12  22  NA  NA   6   f   2   b<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 3:  13  23  11   k   7   g   3   c<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 4:  14  24  12   l   8   h   4   d<\/span>\r\n<span style=\"color: #666666;font-style: italic\"># To make a Left Join between several data.tables we are going \r\n# to create the mergeLeft function which is the merge command \r\n# setting parameter all.x = TRUE; doing this we will force to \r\n# show all data from the left dataset and only data with \r\n# matched key from the right dataset\r\n<\/span>mergeLeft <span>&lt;-<\/span> <a href=\"http:\/\/inside-r.org\/r-doc\/base\/function\"><span style=\"color: #003399;font-weight: bold\">function<\/span><\/a><span style=\"color: #009900\">(<\/span>x<span style=\"color: #339933\">,<\/span> y<span style=\"color: #009900\">)<\/span> <a href=\"http:\/\/inside-r.org\/r-doc\/base\/merge\"><span style=\"color: #003399;font-weight: bold\">merge<\/span><\/a><span style=\"color: #009900\">(<\/span>x<span style=\"color: #339933\">,<\/span> y<span style=\"color: #339933\">,<\/span> all.x = <span style=\"color: #000000;font-weight: bold\">TRUE<\/span><span style=\"color: #009900\">)<\/span>\r\n<span style=\"color: #666666;font-style: italic\"># Left join between Dt1, Dt2 and Dt3 using Reduce and mergeLeft function\u00a0<\/span>\r\n<a href=\"http:\/\/inside-r.org\/r-doc\/base\/Reduce\"><span style=\"color: #003399;font-weight: bold\">Reduce<\/span><\/a><span style=\"color: #009900\">(<\/span>mergeLeft<span style=\"color: #339933\">,<\/span> <a href=\"http:\/\/inside-r.org\/r-doc\/base\/list\"><span style=\"color: #003399;font-weight: bold\">list<\/span><\/a><span style=\"color: #009900\">(<\/span>Dt1<span style=\"color: #339933\">,<\/span> Dt2<span style=\"color: #339933\">,<\/span> Dt3<span style=\"color: #009900\">)<\/span><span style=\"color: #009900\">)<\/span>\r\n<span style=\"color: #666666;font-style: italic\">##    id1 id2 c11 c12 c21 c22 c31 c32<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 1:  11  21   1   a  NA  NA  NA  NA<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 2:  12  22   2   b   6   f  NA  NA<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 3:  13  23   3   c   7   g  11   k<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 4:  14  24   4   d   8   h  12   l<\/span>\r\n\r\n<span style=\"color: #666666;font-style: italic\"># *** FULL JOIN *** <\/span>\r\n<span style=\"color: #666666;font-style: italic\"># In the Full join we want to get all data from both datasets \r\n# regardless of whether or not there are matched keys<\/span>\r\n\r\n<span style=\"color: #666666;font-style: italic\"># Full join between Dt1 y Dt2 with data.table syntax\u00a0 <\/span>\r\n<span style=\"color: #666666;font-style: italic\"># To make a \"Full Join\" with data.table syntax we'll going to \r\n# create an object that contains all the ids we have and use it \r\n# as the index in our join, like this:<\/span>\r\n<span style=\"color: #666666;font-style: italic\"># 1.- Create a variable from the union of 'ids\/keys' <\/span>\r\nids <span>&lt;-<\/span> <a href=\"http:\/\/inside-r.org\/r-doc\/base\/unique\"><span style=\"color: #003399;font-weight: bold\">unique<\/span><\/a><span style=\"color: #009900\">(<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/rbind\"><span style=\"color: #003399;font-weight: bold\">rbind<\/span><\/a><span style=\"color: #009900\">(<\/span>Dt1<span style=\"color: #009900\">[<\/span><span style=\"color: #339933\">,<\/span> <a href=\"http:\/\/inside-r.org\/r-doc\/base\/list\"><span style=\"color: #003399;font-weight: bold\">list<\/span><\/a><span style=\"color: #009900\">(<\/span>id1<span style=\"color: #339933\">,<\/span> id2<span style=\"color: #009900\">)<\/span><span style=\"color: #009900\">]<\/span><span style=\"color: #339933\">,<\/span> Dt2<span style=\"color: #009900\">[<\/span><span style=\"color: #339933\">,<\/span> <a href=\"http:\/\/inside-r.org\/r-doc\/base\/list\"><span style=\"color: #003399;font-weight: bold\">list<\/span><\/a><span style=\"color: #009900\">(<\/span>id1<span style=\"color: #339933\">,<\/span> id2<span style=\"color: #009900\">)<\/span><span style=\"color: #009900\">]<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #009900\">)<\/span>\r\nids\r\n<span style=\"color: #666666;font-style: italic\">##    id1 id2<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 1:  11  21<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 2:  12  22<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 3:  13  23<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 4:  14  24<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 5:  99  98<\/span>\r\n<span style=\"color: #666666;font-style: italic\"># 2.- Full join between Dt1 y Dt2 with data.table syntax\u00a0<\/span>\r\n<span style=\"color: #666666;font-style: italic\"># (using ids object)<\/span>\r\nDt1<span style=\"color: #009900\">[<\/span>Dt2<span style=\"color: #009900\">[<\/span>ids<span style=\"color: #009900\">]<\/span><span style=\"color: #009900\">]<\/span>\r\n<span style=\"color: #666666;font-style: italic\">##    id1 id2 c11 c12 c21 c22<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 1:  11  21   1   a  NA  NA<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 2:  12  22   2   b   6   f<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 3:  13  23   3   c   7   g<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 4:  14  24   4   d   8   h<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 5:  99  98  NA  NA   5   e<\/span>\r\n<span style=\"color: #666666;font-style: italic\"># Full\u00a0join between Dt1 y Dt2, using merge command<\/span>\r\n<a href=\"http:\/\/inside-r.org\/r-doc\/base\/merge\"><span style=\"color: #003399;font-weight: bold\">merge<\/span><\/a><span style=\"color: #009900\">(<\/span>x = Dt1<span style=\"color: #339933\">,<\/span> y = Dt2<span style=\"color: #339933\">,<\/span> <a href=\"http:\/\/inside-r.org\/r-doc\/base\/all\"><span style=\"color: #003399;font-weight: bold\">all<\/span><\/a> = <span style=\"color: #000000;font-weight: bold\">TRUE<\/span><span style=\"color: #009900\">)<\/span>\r\n<span style=\"color: #666666;font-style: italic\">##    id1 id2 c11 c12 c21 c22<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 1:  11  21   1   a  NA  NA<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 2:  12  22   2   b   6   f<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 3:  13  23   3   c   7   g<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 4:  14  24   4   d   8   h<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 5:  99  98  NA  NA   5   e<\/span>\r\n<span style=\"color: #666666;font-style: italic\"># Full join between Dt1, Dt2 and Dt3 with data.table syntax<\/span>\r\n<span style=\"color: #666666;font-style: italic\"># 1.- Create a variable from the union of 'ids\/keys' <\/span>\r\nids <span>&lt;-<\/span> <a href=\"http:\/\/inside-r.org\/r-doc\/base\/unique\"><span style=\"color: #003399;font-weight: bold\">unique<\/span><\/a><span style=\"color: #009900\">(<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/rbind\"><span style=\"color: #003399;font-weight: bold\">rbind<\/span><\/a><span style=\"color: #009900\">(<\/span>Dt1<span style=\"color: #009900\">[<\/span><span style=\"color: #339933\">,<\/span> <a href=\"http:\/\/inside-r.org\/r-doc\/base\/list\"><span style=\"color: #003399;font-weight: bold\">list<\/span><\/a><span style=\"color: #009900\">(<\/span>id1<span style=\"color: #339933\">,<\/span> id2<span style=\"color: #009900\">)<\/span><span style=\"color: #009900\">]<\/span><span style=\"color: #339933\">,<\/span> Dt2<span style=\"color: #009900\">[<\/span><span style=\"color: #339933\">,<\/span> <a href=\"http:\/\/inside-r.org\/r-doc\/base\/list\"><span style=\"color: #003399;font-weight: bold\">list<\/span><\/a><span style=\"color: #009900\">(<\/span>id1<span style=\"color: #339933\">,<\/span> id2<span style=\"color: #009900\">)<\/span><span style=\"color: #009900\">]<\/span><span style=\"color: #339933\">,<\/span> Dt3<span style=\"color: #009900\">[<\/span><span style=\"color: #339933\">,<\/span> <a href=\"http:\/\/inside-r.org\/r-doc\/base\/list\"><span style=\"color: #003399;font-weight: bold\">list<\/span><\/a><span style=\"color: #009900\">(<\/span>id1<span style=\"color: #339933\">,<\/span> id2<span style=\"color: #009900\">)<\/span><span style=\"color: #009900\">]<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #009900\">)<\/span>\r\nids\r\n<span style=\"color: #666666;font-style: italic\">##     id1  id2<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 1:   11   21<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 2:   12   22<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 3:   13   23<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 4:   14   24<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 5:   99   98<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 6:  999  998<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 7: 9999 9998<\/span>\r\n<span style=\"color: #666666;font-style: italic\"># 2.- Full join between Dt1 y Dt2 with data.table syntax<\/span>\r\n<span style=\"color: #666666;font-style: italic\"># (using ids object)<\/span>\r\nDt1<span style=\"color: #009900\">[<\/span>Dt2<span style=\"color: #009900\">[<\/span>Dt3<span style=\"color: #009900\">[<\/span>ids<span style=\"color: #009900\">]<\/span><span style=\"color: #009900\">]<\/span><span style=\"color: #009900\">]<\/span>\r\n<span style=\"color: #666666;font-style: italic\">##     id1  id2 c11 c12 c21 c22 c31 c32<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 1:   11   21   1   a  NA  NA  NA  NA<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 2:   12   22   2   b   6   f  NA  NA<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 3:   13   23   3   c   7   g  11   k<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 4:   14   24   4   d   8   h  12   l<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 5:   99   98  NA  NA   5   e  NA  NA<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 6:  999  998  NA  NA  NA  NA   9   i<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 7: 9999 9998  NA  NA  NA  NA  10   j<\/span>\r\n<span style=\"color: #666666;font-style: italic\"># To make a Full Join between several data.tables we are going \r\n# to create the mergeFull function which is the merge command \r\n# setting parameter all = TRUE; doing this we will force to \r\n# show all data from both dataset\r\n<\/span>mergeFull <span>&lt;-<\/span> <a href=\"http:\/\/inside-r.org\/r-doc\/base\/function\"><span style=\"color: #003399;font-weight: bold\">function<\/span><\/a><span style=\"color: #009900\">(<\/span>x<span style=\"color: #339933\">,<\/span> y<span style=\"color: #009900\">)<\/span> <a href=\"http:\/\/inside-r.org\/r-doc\/base\/merge\"><span style=\"color: #003399;font-weight: bold\">merge<\/span><\/a><span style=\"color: #009900\">(<\/span>x<span style=\"color: #339933\">,<\/span> y<span style=\"color: #339933\">,<\/span> <a href=\"http:\/\/inside-r.org\/r-doc\/base\/all\"><span style=\"color: #003399;font-weight: bold\">all<\/span><\/a> = <span style=\"color: #000000;font-weight: bold\">TRUE<\/span><span style=\"color: #009900\">)<\/span>\r\n<span style=\"color: #666666;font-style: italic\"># Full join between Dt1, Dt2 and Dt3 using Reduce and mergeFull function\u00a0<\/span>\r\n<a href=\"http:\/\/inside-r.org\/r-doc\/base\/Reduce\"><span style=\"color: #003399;font-weight: bold\">Reduce<\/span><\/a><span style=\"color: #009900\">(<\/span>mergeFull<span style=\"color: #339933\">,<\/span> <a href=\"http:\/\/inside-r.org\/r-doc\/base\/list\"><span style=\"color: #003399;font-weight: bold\">list<\/span><\/a><span style=\"color: #009900\">(<\/span>Dt1<span style=\"color: #339933\">,<\/span> Dt2<span style=\"color: #339933\">,<\/span> Dt3<span style=\"color: #009900\">)<\/span><span style=\"color: #009900\">)<\/span>\r\n<span style=\"color: #666666;font-style: italic\">##     id1  id2 c11 c12 c21 c22 c31 c32<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 1:   11   21   1   a  NA  NA  NA  NA<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 2:   12   22   2   b   6   f  NA  NA<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 3:   13   23   3   c   7   g  11   k<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 4:   14   24   4   d   8   h  12   l<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 5:   99   98  NA  NA   5   e  NA  NA<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 6:  999  998  NA  NA  NA  NA   9   i<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 7: 9999 9998  NA  NA  NA  NA  10   j<\/span>\r\n\r\n<span style=\"color: #666666;font-style: italic\"># *** PARA AUMENTAR FILAS - RBIND ***<\/span>\r\n<span style=\"color: #666666;font-style: italic\"># The rbind command is used to increase the rows of \r\n# a dataset under the other, the following will fail \r\n# since the variables are not the same name<\/span>\r\n<a href=\"http:\/\/inside-r.org\/r-doc\/base\/rbind\"><span style=\"color: #003399;font-weight: bold\">rbind<\/span><\/a><span style=\"color: #009900\">(<\/span>Dt1<span style=\"color: #339933\">,<\/span> Dt2<span style=\"color: #009900\">)<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## Error: Some colnames of argument 2 (c21,c22) are not present in colnames<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## of item 1. If an argument has colnames they can be in a different order,<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## but they must all be present. Alternatively, you can drop names (by using<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## an unnamed list) and the columns will then be joined by position. Or, set<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## use.names=FALSE.<\/span>\r\n\r\n<span style=\"color: #666666;font-style: italic\"># *** PARA AUMENTAR COLUMNAS - CBIND *** <\/span>\r\n<span style=\"color: #666666;font-style: italic\"># The command cbind columns is used to increase the columns \r\n# of a data set to another. Here you can see how the cbind \r\n# (without options) does not respect the indices simply \r\n# puts a whole dataset beside the other (see the order of \"ids\" )<\/span>\r\n<a href=\"http:\/\/inside-r.org\/r-doc\/base\/cbind\"><span style=\"color: #003399;font-weight: bold\">cbind<\/span><\/a><span style=\"color: #009900\">(<\/span>Dt1<span style=\"color: #339933\">,<\/span> Dt2<span style=\"color: #009900\">)<\/span>\r\n<span style=\"color: #666666;font-style: italic\">##    id1 id2 c11 c12 id1 id2 c21 c22<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 1:  11  21   1   a  12  22   6   f<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 2:  12  22   2   b  13  23   7   g<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 3:  13  23   3   c  14  24   8   h<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 4:  14  24   4   d  99  98   5   e<\/span>\r\n<a href=\"http:\/\/inside-r.org\/r-doc\/base\/cbind\"><span style=\"color: #003399;font-weight: bold\">cbind<\/span><\/a><span style=\"color: #009900\">(<\/span>Dt1<span style=\"color: #339933\">,<\/span> Dt2<span style=\"color: #339933\">,<\/span> Dt3<span style=\"color: #009900\">)<\/span>\r\n<span style=\"color: #666666;font-style: italic\">##    id1 id2 c11 c12 id1 id2 c21 c22  id1  id2 c31 c32<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 1:  11  21   1   a  12  22   6   f   13   23  11   k<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 2:  12  22   2   b  13  23   7   g   14   24  12   l<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 3:  13  23   3   c  14  24   8   h  999  998   9   i<\/span>\r\n<span style=\"color: #666666;font-style: italic\">## 4:  14  24   4   d  99  98   5   e 9999 9998  10   j<\/span><\/pre>\n<\/div>\n<\/div>\n<p><a title=\"Created by Pretty R at inside-R.org\" href=\"http:\/\/www.inside-r.org\/pretty-r\">Created by Pretty R at inside-R.org<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>The perceptive reader will have noticed how to do a Left Join without having the problem with the order of the columns... I leave you the question.<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Someone this week ask me about how to make joins using data.table objects, this person was doubting whether it was right to use: merge, rbind o cbind; so I've made this blog post leveraging the script that we used to explain the differences.<\/p><p><a class=\"more-link btn\" href=\"https:\/\/blog.espol.edu.ec\/nemo\/2013\/12\/23\/merge-data-a-review-of-the-differences-between-merge-inner-join-left-join-right-join-full-join-cbind-and-rbind-when-used-data-table-objects-in-r\/\">Seguir leyendo<\/a><\/p>\n","protected":false},"author":3803,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1688,1534],"tags":[356627,356626,356629,356631,1171628,356635,393,356632,42702,356633,42704,356648,356647,356646,356639,1171627,356625,356634,4709,356636,356637,356640,356628],"class_list":["post-367","post","type-post","status-publish","format-standard","hentry","category-estadistica","category-r","tag-buscarv","tag-cbind","tag-data-table","tag-dtx","tag-estadistica","tag-full-join","tag-informatica","tag-inner-join","tag-join","tag-left-join","tag-merge","tag-merge-dataset","tag-merge-several-datasets","tag-merge-table","tag-multiple-merge","tag-r","tag-rbind","tag-right-join","tag-union","tag-unir-data-tables","tag-unir-tablas","tag-unir-varios-conjuntos-de-datos","tag-vlookup","item-wrap"],"_links":{"self":[{"href":"https:\/\/blog.espol.edu.ec\/nemo\/wp-json\/wp\/v2\/posts\/367","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.espol.edu.ec\/nemo\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.espol.edu.ec\/nemo\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.espol.edu.ec\/nemo\/wp-json\/wp\/v2\/users\/3803"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.espol.edu.ec\/nemo\/wp-json\/wp\/v2\/comments?post=367"}],"version-history":[{"count":13,"href":"https:\/\/blog.espol.edu.ec\/nemo\/wp-json\/wp\/v2\/posts\/367\/revisions"}],"predecessor-version":[{"id":381,"href":"https:\/\/blog.espol.edu.ec\/nemo\/wp-json\/wp\/v2\/posts\/367\/revisions\/381"}],"wp:attachment":[{"href":"https:\/\/blog.espol.edu.ec\/nemo\/wp-json\/wp\/v2\/media?parent=367"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.espol.edu.ec\/nemo\/wp-json\/wp\/v2\/categories?post=367"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.espol.edu.ec\/nemo\/wp-json\/wp\/v2\/tags?post=367"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}