{"id":947,"date":"2023-07-28T05:30:58","date_gmt":"2023-07-28T05:30:58","guid":{"rendered":"https:\/\/statorials.org\/pt\/junte-varios-dataframes-dplyr\/"},"modified":"2023-07-28T05:30:58","modified_gmt":"2023-07-28T05:30:58","slug":"junte-varios-dataframes-dplyr","status":"publish","type":"post","link":"https:\/\/statorials.org\/pt\/junte-varios-dataframes-dplyr\/","title":{"rendered":"Como juntar v\u00e1rios frames de dados usando dplyr"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Freq\u00fcentemente, voc\u00ea pode estar interessado em unir v\u00e1rios quadros de dados em R. Felizmente, isso \u00e9 f\u00e1cil de fazer usando a fun\u00e7\u00e3o <a href=\"https:\/\/dplyr.tidyverse.org\/reference\/mutate-joins.html\" target=\"_blank\" rel=\"noopener noreferrer\">left_join()<\/a><\/span> <span style=\"color: #000000;\">do pacote <a href=\"https:\/\/dplyr.tidyverse.org\/\" target=\"_blank\" rel=\"noopener noreferrer\">dplyr<\/a> .<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>library(dplyr)<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Por exemplo, suponha que temos os tr\u00eas quadros de dados a seguir:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#create data frame<\/span>\ndf1 &lt;- data.frame(a = c('a', 'b', 'c', 'd', 'e', 'f'),\n                  b = c(12, 14, 14, 18, 22, 23))\n\ndf2 &lt;- data.frame(a = c('a', 'a', 'a', 'b', 'b', 'b'),\n                  c = c(23, 24, 33, 34, 37, 41))\n\ndf3 &lt;- data.frame(a = c('d', 'e', 'f', 'g', 'h', 'i'),\n                  d = c(23, 24, 33, 34, 37, 41))\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Para unir os tr\u00eas quadros de dados, podemos simplesmente fazer duas jun\u00e7\u00f5es \u00e0 esquerda, uma ap\u00f3s a outra:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#join the three data frames<\/span>\ndf1 %&gt;%\n    <span style=\"color: #3366ff;\">left_join<\/span> (df2, by='a') %&gt;%\n    <span style=\"color: #3366ff;\">left_join<\/span> (df3, by='a')\n\n   abcd\n1 to 12 23 NA\n2 to 12 24 NA\n3 to 12 33 NA\n4 b 14 34 NA\n5 b 14 37 NA\n6 b 14 41 NA\n7 c 14 NA NA\n8 d 18 NA 23\n9th 22 NA 24\n10 f 23 NA 33\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Observe que voc\u00ea tamb\u00e9m pode salvar o resultado dessa jun\u00e7\u00e3o como um quadro de dados:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#join the three data frames and save result as new data frame named all_data<\/span>\nall_data &lt;- df1 %&gt;%\n              <span style=\"color: #3366ff;\">left_join<\/span> (df2, by='a') %&gt;%\n              <span style=\"color: #3366ff;\">left_join<\/span> (df3, by='a')\n\n<span style=\"color: #008080;\">#view summary of resulting data frame\n<\/span>glimpse(all_data)\n\nComments: 10\nVariables: 4\n$ a &lt;chr&gt; \"a\", \"a\", \"a\", \"b\", \"b\", \"b\", \"c\", \"d\", \"e\", \"f\"\n$b&lt;dbl&gt; 12, 12, 12, 14, 14, 14, 14, 18, 22, 23\n$ c &lt;dbl&gt; 23, 24, 33, 34, 37, 41, NA, NA, NA, NA\n$ d &lt;dbl&gt; NA, NA, NA, NA, NA, NA, NA, 23, 24, 33\n<\/strong><\/pre>\n<h3> <span style=\"color: #000000;\"><strong>Recursos adicionais<\/strong><\/span><\/h3>\n<p> <a href=\"https:\/\/statorials.org\/pt\/filtrar-linhas-r\/\" target=\"_blank\" rel=\"noopener noreferrer\">Como filtrar linhas em R<\/a><br \/> <a href=\"https:\/\/statorials.org\/pt\/estatologia-explica-conceitos-de-forma-simples-e-direta-facilitamos-o-aprendizado-de-estatistica\/\" target=\"_blank\" rel=\"noopener noreferrer\">Como remover linhas duplicadas em R<\/a><br \/> <a href=\"https:\/\/statorials.org\/pt\/dados-de-curriculo-do-grupo-r\/\" target=\"_blank\" rel=\"noopener noreferrer\">Como agrupar e resumir dados em R<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Freq\u00fcentemente, voc\u00ea pode estar interessado em unir v\u00e1rios quadros de dados em R. Felizmente, isso \u00e9 f\u00e1cil de fazer usando a fun\u00e7\u00e3o left_join() do pacote dplyr . library(dplyr) Por exemplo, suponha que temos os tr\u00eas quadros de dados a seguir: #create data frame df1 &lt;- data.frame(a = c(&#8216;a&#8217;, &#8216;b&#8217;, &#8216;c&#8217;, &#8216;d&#8217;, &#8216;e&#8217;, &#8216;f&#8217;), b = [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-947","post","type-post","status-publish","format-standard","hentry","category-guia"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Como juntar v\u00e1rios frames de dados usando dplyr - Statorials<\/title>\n<meta name=\"description\" content=\"Uma explica\u00e7\u00e3o simples sobre como juntar v\u00e1rios quadros de dados em R usando dplyr.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/statorials.org\/pt\/junte-varios-dataframes-dplyr\/\" \/>\n<meta property=\"og:locale\" content=\"pt_PT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Como juntar v\u00e1rios frames de dados usando dplyr - Statorials\" \/>\n<meta property=\"og:description\" content=\"Uma explica\u00e7\u00e3o simples sobre como juntar v\u00e1rios quadros de dados em R usando dplyr.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/pt\/junte-varios-dataframes-dplyr\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-28T05:30:58+00:00\" \/>\n<meta name=\"author\" content=\"Dr. benjamim anderson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Escrito por\" \/>\n\t<meta name=\"twitter:data1\" content=\"Dr. benjamim anderson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Tempo estimado de leitura\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minuto\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/pt\/junte-varios-dataframes-dplyr\/\",\"url\":\"https:\/\/statorials.org\/pt\/junte-varios-dataframes-dplyr\/\",\"name\":\"Como juntar v\u00e1rios frames de dados usando dplyr - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/pt\/#website\"},\"datePublished\":\"2023-07-28T05:30:58+00:00\",\"dateModified\":\"2023-07-28T05:30:58+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666\"},\"description\":\"Uma explica\u00e7\u00e3o simples sobre como juntar v\u00e1rios quadros de dados em R usando dplyr.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/pt\/junte-varios-dataframes-dplyr\/#breadcrumb\"},\"inLanguage\":\"pt-PT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/pt\/junte-varios-dataframes-dplyr\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/pt\/junte-varios-dataframes-dplyr\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Lar\",\"item\":\"https:\/\/statorials.org\/pt\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Como juntar v\u00e1rios frames de dados usando dplyr\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/statorials.org\/pt\/#website\",\"url\":\"https:\/\/statorials.org\/pt\/\",\"name\":\"Statorials\",\"description\":\"O seu guia para a literacia estat\u00edstica!\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/statorials.org\/pt\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"pt-PT\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666\",\"name\":\"Dr. benjamim anderson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"pt-PT\",\"@id\":\"https:\/\/statorials.org\/pt\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/statorials.org\/pt\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"contentUrl\":\"https:\/\/statorials.org\/pt\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"caption\":\"Dr. benjamim anderson\"},\"description\":\"Ol\u00e1, sou Benjamin, um professor aposentado de estat\u00edstica que se tornou professor dedicado na Statorials. Com vasta experi\u00eancia e conhecimento na \u00e1rea de estat\u00edstica, estou empenhado em compartilhar meu conhecimento para capacitar os alunos por meio de Statorials. Saber mais\",\"sameAs\":[\"https:\/\/statorials.org\/pt\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Como juntar v\u00e1rios frames de dados usando dplyr - Statorials","description":"Uma explica\u00e7\u00e3o simples sobre como juntar v\u00e1rios quadros de dados em R usando dplyr.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/statorials.org\/pt\/junte-varios-dataframes-dplyr\/","og_locale":"pt_PT","og_type":"article","og_title":"Como juntar v\u00e1rios frames de dados usando dplyr - Statorials","og_description":"Uma explica\u00e7\u00e3o simples sobre como juntar v\u00e1rios quadros de dados em R usando dplyr.","og_url":"https:\/\/statorials.org\/pt\/junte-varios-dataframes-dplyr\/","og_site_name":"Statorials","article_published_time":"2023-07-28T05:30:58+00:00","author":"Dr. benjamim anderson","twitter_card":"summary_large_image","twitter_misc":{"Escrito por":"Dr. benjamim anderson","Tempo estimado de leitura":"1 minuto"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/pt\/junte-varios-dataframes-dplyr\/","url":"https:\/\/statorials.org\/pt\/junte-varios-dataframes-dplyr\/","name":"Como juntar v\u00e1rios frames de dados usando dplyr - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/pt\/#website"},"datePublished":"2023-07-28T05:30:58+00:00","dateModified":"2023-07-28T05:30:58+00:00","author":{"@id":"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666"},"description":"Uma explica\u00e7\u00e3o simples sobre como juntar v\u00e1rios quadros de dados em R usando dplyr.","breadcrumb":{"@id":"https:\/\/statorials.org\/pt\/junte-varios-dataframes-dplyr\/#breadcrumb"},"inLanguage":"pt-PT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/pt\/junte-varios-dataframes-dplyr\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/pt\/junte-varios-dataframes-dplyr\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Lar","item":"https:\/\/statorials.org\/pt\/"},{"@type":"ListItem","position":2,"name":"Como juntar v\u00e1rios frames de dados usando dplyr"}]},{"@type":"WebSite","@id":"https:\/\/statorials.org\/pt\/#website","url":"https:\/\/statorials.org\/pt\/","name":"Statorials","description":"O seu guia para a literacia estat\u00edstica!","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/statorials.org\/pt\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"pt-PT"},{"@type":"Person","@id":"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666","name":"Dr. benjamim anderson","image":{"@type":"ImageObject","inLanguage":"pt-PT","@id":"https:\/\/statorials.org\/pt\/#\/schema\/person\/image\/","url":"https:\/\/statorials.org\/pt\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","contentUrl":"https:\/\/statorials.org\/pt\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","caption":"Dr. benjamim anderson"},"description":"Ol\u00e1, sou Benjamin, um professor aposentado de estat\u00edstica que se tornou professor dedicado na Statorials. Com vasta experi\u00eancia e conhecimento na \u00e1rea de estat\u00edstica, estou empenhado em compartilhar meu conhecimento para capacitar os alunos por meio de Statorials. Saber mais","sameAs":["https:\/\/statorials.org\/pt"]}]}},"yoast_meta":{"yoast_wpseo_title":"","yoast_wpseo_metadesc":"","yoast_wpseo_canonical":""},"_links":{"self":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/posts\/947","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/comments?post=947"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/posts\/947\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/media?parent=947"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/categories?post=947"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/tags?post=947"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}