{"id":2942,"date":"2023-07-20T00:06:16","date_gmt":"2023-07-20T00:06:16","guid":{"rendered":"https:\/\/statorials.org\/it\/a-destra-unisciti-a-r\/"},"modified":"2023-07-20T00:06:16","modified_gmt":"2023-07-20T00:06:16","slug":"a-destra-unisciti-a-r","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/a-destra-unisciti-a-r\/","title":{"rendered":"Come eseguire un right join in r (con esempi)"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Esistono due modi comuni per eseguire un join destro in R:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Metodo 1: utilizzare Base R<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>merge(df1, df2, by=' <span style=\"color: #ff0000;\">column_to_join_on<\/span> ', all. <span style=\"color: #3366ff;\">y<\/span> = <span style=\"color: #008000;\">TRUE<\/span> )\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\"><strong>Metodo 2: usa dplyr<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #000000;\"><span style=\"color: #008000;\">library<\/span> (dplyr)\n\n<\/span>right_join(df1, df2, by=' <span style=\"color: #ff0000;\">column_to_join_on<\/span> ')<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Entrambi i metodi restituiranno tutte le righe da <strong>df2<\/strong> e tutte le righe con chiavi corrispondenti da <strong>df1<\/strong> .<\/span><\/p>\n<p> <span style=\"color: #000000;\">Vale anche la pena notare che entrambi i metodi produrranno lo stesso risultato, ma il metodo dplyr tender\u00e0 a funzionare pi\u00f9 velocemente su set di dati estremamente grandi.<\/span><\/p>\n<p> <span style=\"color: #000000;\">I seguenti esempi mostrano come utilizzare nella pratica ciascuna di queste funzioni con i seguenti frame di dati:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#define first data frame\n<\/span>df1 = data. <span style=\"color: #3366ff;\">frame<\/span> (team=c('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'),\n                 points=c(18, 22, 19, 14, 14, 11, 20, 28))\n\ndf1\n\n  team points\n1 to 18\n2 B 22\n3 C 19\n4 D 14\n5 E 14\n6 F 11\n7 G 20\n8:28 a.m.\n\n<span style=\"color: #008080;\">#define second data frame\n<\/span>df2 = data. <span style=\"color: #3366ff;\">frame<\/span> (team=c('A', 'B', 'C', 'D', 'L', 'M'),\n                 assists=c(4, 9, 14, 13, 10, 8))\n\ndf2\n\n  team assists\n1 to 4\n2 B 9\n3 C 14\n4 D 13\n5 L 10\n6 M 8<\/strong><\/pre>\n<h3> <span style=\"color: #000000;\"><strong>Esempio 1: unione a destra utilizzando Base R<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Possiamo usare la funzione <strong>merge()<\/strong> in base R per eseguire un right join, utilizzando la colonna &#8216;team&#8217; come colonna a cui unirsi:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#perform right join using base R<\/span>\ndf3 &lt;- merge(df1, df2, by=' <span style=\"color: #ff0000;\">team<\/span> ', all. <span style=\"color: #3366ff;\">y<\/span> = <span style=\"color: #008000;\">TRUE<\/span> )\n\n<span style=\"color: #008080;\">#view result<\/span>\ndf3\n\n  team points assists\n1 to 18 4\n2 B 22 9\n3 C 19 14\n4 D 14 13\n5 L NA 10\n6 M NA 8\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Si noti che tutte le righe di <strong>df2<\/strong> sono state incluse nel frame di dati finale, ma solo le righe di <strong>df1<\/strong> che avevano un nome di squadra corrispondente sono state incluse nel frame di dati finale.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Esempio 2: join destro utilizzando dplyr<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Possiamo usare la funzione <strong>right_join()<\/strong> dal pacchetto <a href=\"https:\/\/dplyr.tidyverse.org\/\" target=\"_blank\" rel=\"noopener\">dplyr<\/a> per eseguire un right join, utilizzando la colonna &#8216;team&#8217; come colonna a cui unirsi:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\">library<\/span> (dplyr)\n\n<span style=\"color: #008080;\">#perform right join using dplyr<\/span> \ndf3 &lt;- right_join(df1, df2, by=' <span style=\"color: #ff0000;\">team<\/span> ')\n\n<span style=\"color: #008080;\">#view result\n<\/span>df3\n\n  team points assists\n1 to 18 4\n2 B 22 9\n3 C 19 14\n4 D 14 13\n5 L NA 10\n6 M NA 8<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Nota che questo corrisponde al risultato che abbiamo ottenuto utilizzando la funzione <strong>merge()<\/strong> in base R.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Risorse addizionali<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">I seguenti tutorial spiegano come eseguire altre operazioni comuni in R:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/it\/a-sinistra-unisciti-a-r\/\" target=\"_blank\" rel=\"noopener\">Come eseguire un join a sinistra in R<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/r-aggiungi-una-colonna-al-dataframe\/\" target=\"_blank\" rel=\"noopener\">Come aggiungere una colonna al frame di dati in R<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/r-colonna-mobile\/\" target=\"_blank\" rel=\"noopener\">Come rimuovere le colonne dal frame di dati in R<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Esistono due modi comuni per eseguire un join destro in R: Metodo 1: utilizzare Base R merge(df1, df2, by=&#8217; column_to_join_on &#8216;, all. y = TRUE ) Metodo 2: usa dplyr library (dplyr) right_join(df1, df2, by=&#8217; column_to_join_on &#8216;) Entrambi i metodi restituiranno tutte le righe da df2 e tutte le righe con chiavi corrispondenti da df1 [&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":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Come eseguire un join destro in R (con esempi) \u2013 Statorials<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come eseguire un join destro in R, con diversi esempi.\" \/>\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\/it\/a-destra-unisciti-a-r\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Come eseguire un join destro in R (con esempi) \u2013 Statorials\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come eseguire un join destro in R, con diversi esempi.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/a-destra-unisciti-a-r\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-20T00:06:16+00:00\" \/>\n<meta name=\"author\" content=\"Benjamin anderson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Benjamin anderson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minuti\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/it\/a-destra-unisciti-a-r\/\",\"url\":\"https:\/\/statorials.org\/it\/a-destra-unisciti-a-r\/\",\"name\":\"Come eseguire un join destro in R (con esempi) \u2013 Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-20T00:06:16+00:00\",\"dateModified\":\"2023-07-20T00:06:16+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come eseguire un join destro in R, con diversi esempi.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/a-destra-unisciti-a-r\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/a-destra-unisciti-a-r\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/a-destra-unisciti-a-r\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Come eseguire un right join in r (con esempi)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/statorials.org\/it\/#website\",\"url\":\"https:\/\/statorials.org\/it\/\",\"name\":\"Statorials\",\"description\":\"La tua guida all&#039;alfabetizzazione statistica!\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/statorials.org\/it\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"it-IT\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\",\"name\":\"Benjamin anderson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"it-IT\",\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/statorials.org\/it\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"contentUrl\":\"https:\/\/statorials.org\/it\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"caption\":\"Benjamin anderson\"},\"description\":\"Ciao, sono Benjamin, un professore di statistica in pensione diventato insegnante dedicato di Statorials. Con una vasta esperienza e competenza nel campo della statistica, sono ansioso di condividere le mie conoscenze per potenziare gli studenti attraverso Statorials. Scopri di pi\u00f9\",\"sameAs\":[\"https:\/\/statorials.org\/it\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Come eseguire un join destro in R (con esempi) \u2013 Statorials","description":"Questo tutorial spiega come eseguire un join destro in R, con diversi esempi.","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\/it\/a-destra-unisciti-a-r\/","og_locale":"it_IT","og_type":"article","og_title":"Come eseguire un join destro in R (con esempi) \u2013 Statorials","og_description":"Questo tutorial spiega come eseguire un join destro in R, con diversi esempi.","og_url":"https:\/\/statorials.org\/it\/a-destra-unisciti-a-r\/","og_site_name":"Statorials","article_published_time":"2023-07-20T00:06:16+00:00","author":"Benjamin anderson","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Benjamin anderson","Est. reading time":"2 minuti"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/it\/a-destra-unisciti-a-r\/","url":"https:\/\/statorials.org\/it\/a-destra-unisciti-a-r\/","name":"Come eseguire un join destro in R (con esempi) \u2013 Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-20T00:06:16+00:00","dateModified":"2023-07-20T00:06:16+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come eseguire un join destro in R, con diversi esempi.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/a-destra-unisciti-a-r\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/a-destra-unisciti-a-r\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/a-destra-unisciti-a-r\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Come eseguire un right join in r (con esempi)"}]},{"@type":"WebSite","@id":"https:\/\/statorials.org\/it\/#website","url":"https:\/\/statorials.org\/it\/","name":"Statorials","description":"La tua guida all&#039;alfabetizzazione statistica!","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/statorials.org\/it\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"it-IT"},{"@type":"Person","@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae","name":"Benjamin anderson","image":{"@type":"ImageObject","inLanguage":"it-IT","@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/image\/","url":"https:\/\/statorials.org\/it\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","contentUrl":"https:\/\/statorials.org\/it\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","caption":"Benjamin anderson"},"description":"Ciao, sono Benjamin, un professore di statistica in pensione diventato insegnante dedicato di Statorials. Con una vasta esperienza e competenza nel campo della statistica, sono ansioso di condividere le mie conoscenze per potenziare gli studenti attraverso Statorials. Scopri di pi\u00f9","sameAs":["https:\/\/statorials.org\/it"]}]}},"yoast_meta":{"yoast_wpseo_title":"","yoast_wpseo_metadesc":"","yoast_wpseo_canonical":""},"_links":{"self":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/2942"}],"collection":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/comments?post=2942"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/2942\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=2942"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=2942"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=2942"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}