merge multiple tables with different length
I want to merge 3 tables together in 1 dataframe. All the tables have a common column ID.
Table1 ID F/M Table2 ID US-citizen Table3 ID Job
10 F 10 1 10 0
11 F 15 1 14 1
12 F 16 1 16 1
13 F 17 0 17 1
14 M 20 1
15 F
16 M
17 M
18 F
19 F
20 M
My expected result:
Table1 ID F/M US-citizen Job
10 F 1 0
11 F NA NA
12 F NA NA
13 F NA NA
14 M NA 1
15 F 1 NA
16 M 1 1
17 M 0 1
18 F NA NA
19 F NA NA
20 M 1 NA
I tried using the merge function:
merge (table1,table2,table3, by= ID)
This will only work for two tables. Is there a way I can get it done for multiple tables?
merge rstudio
add a comment |
I want to merge 3 tables together in 1 dataframe. All the tables have a common column ID.
Table1 ID F/M Table2 ID US-citizen Table3 ID Job
10 F 10 1 10 0
11 F 15 1 14 1
12 F 16 1 16 1
13 F 17 0 17 1
14 M 20 1
15 F
16 M
17 M
18 F
19 F
20 M
My expected result:
Table1 ID F/M US-citizen Job
10 F 1 0
11 F NA NA
12 F NA NA
13 F NA NA
14 M NA 1
15 F 1 NA
16 M 1 1
17 M 0 1
18 F NA NA
19 F NA NA
20 M 1 NA
I tried using the merge function:
merge (table1,table2,table3, by= ID)
This will only work for two tables. Is there a way I can get it done for multiple tables?
merge rstudio
How about merge(merge(df1, df2, by='id', all=T), df3, by='id', all=T)? or use cbind method?
– kon_u
Nov 20 '18 at 10:37
add a comment |
I want to merge 3 tables together in 1 dataframe. All the tables have a common column ID.
Table1 ID F/M Table2 ID US-citizen Table3 ID Job
10 F 10 1 10 0
11 F 15 1 14 1
12 F 16 1 16 1
13 F 17 0 17 1
14 M 20 1
15 F
16 M
17 M
18 F
19 F
20 M
My expected result:
Table1 ID F/M US-citizen Job
10 F 1 0
11 F NA NA
12 F NA NA
13 F NA NA
14 M NA 1
15 F 1 NA
16 M 1 1
17 M 0 1
18 F NA NA
19 F NA NA
20 M 1 NA
I tried using the merge function:
merge (table1,table2,table3, by= ID)
This will only work for two tables. Is there a way I can get it done for multiple tables?
merge rstudio
I want to merge 3 tables together in 1 dataframe. All the tables have a common column ID.
Table1 ID F/M Table2 ID US-citizen Table3 ID Job
10 F 10 1 10 0
11 F 15 1 14 1
12 F 16 1 16 1
13 F 17 0 17 1
14 M 20 1
15 F
16 M
17 M
18 F
19 F
20 M
My expected result:
Table1 ID F/M US-citizen Job
10 F 1 0
11 F NA NA
12 F NA NA
13 F NA NA
14 M NA 1
15 F 1 NA
16 M 1 1
17 M 0 1
18 F NA NA
19 F NA NA
20 M 1 NA
I tried using the merge function:
merge (table1,table2,table3, by= ID)
This will only work for two tables. Is there a way I can get it done for multiple tables?
merge rstudio
merge rstudio
asked Nov 19 '18 at 12:27
Bob Outlook
394
394
How about merge(merge(df1, df2, by='id', all=T), df3, by='id', all=T)? or use cbind method?
– kon_u
Nov 20 '18 at 10:37
add a comment |
How about merge(merge(df1, df2, by='id', all=T), df3, by='id', all=T)? or use cbind method?
– kon_u
Nov 20 '18 at 10:37
How about merge(merge(df1, df2, by='id', all=T), df3, by='id', all=T)? or use cbind method?
– kon_u
Nov 20 '18 at 10:37
How about merge(merge(df1, df2, by='id', all=T), df3, by='id', all=T)? or use cbind method?
– kon_u
Nov 20 '18 at 10:37
add a comment |
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53374644%2fmerge-multiple-tables-with-different-length%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53374644%2fmerge-multiple-tables-with-different-length%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
How about merge(merge(df1, df2, by='id', all=T), df3, by='id', all=T)? or use cbind method?
– kon_u
Nov 20 '18 at 10:37