{"id":1914,"date":"2023-07-24T11:46:40","date_gmt":"2023-07-24T11:46:40","guid":{"rendered":"https:\/\/statorials.org\/it\/confrontare-due-vettori-in-r\/"},"modified":"2023-07-24T11:46:40","modified_gmt":"2023-07-24T11:46:40","slug":"confrontare-due-vettori-in-r","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/confrontare-due-vettori-in-r\/","title":{"rendered":"Come confrontare due vettori in r (con esempi)"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">\u00c8 possibile utilizzare la seguente sintassi di base per confrontare due vettori in R:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#check if two vectors are identical<\/span>\nidentical(vector_1, vector_2)\n\n<span style=\"color: #008080;\">#display items that are in both vectors\n<\/span>intersect(vector_1, vector_2)\n\n<span style=\"color: #008080;\">#display items that are only in first vector, but not in second vector<\/span>\nsetdiff(vector_1, vector_2)\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Gli esempi seguenti mostrano come utilizzare questa sintassi nella pratica.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Esempio 1: controlla se due vettori sono uguali<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come utilizzare la funzione <strong>identico()<\/strong> per verificare se due vettori sono identici:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#definevectors\n<span style=\"color: #000000;\">vector_1 &lt;- c('Andy', 'Bob', 'Carl', 'Doug')\nvector_2 &lt;- c('Bob', 'Carl', 'Doug', 'Ethan', 'Fred')<\/span>\n\n#check if two vectors are identical<\/span>\nidentical(vector_1, vector_2)\n\n[1] FALSE\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">I due vettori non sono identici, quindi viene restituito un valore <strong>FALSO<\/strong> .<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Esempio 2: trova gli elementi che esistono in entrambi i vettori<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come utilizzare la funzione <strong>intersect()<\/strong> per visualizzare gli elementi presenti in entrambi i vettori:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#definevectors\n<span style=\"color: #000000;\">vector_1 &lt;- c('Andy', 'Bob', 'Carl', 'Doug')\nvector_2 &lt;- c('Bob', 'Carl', 'Doug', 'Ethan', 'Fred')<\/span>\n\n#display items that exist in both vectors<\/span>\nintersect(vector_1, vector_2)\n\n[1] \u201cBob\u201d \u201cCarl\u201d \u201cDoug\u201d\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Vengono mostrati i tre elementi che esistono in entrambi i vettori.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Possiamo anche usare la funzione <strong>length()<\/strong> se vogliamo semplicemente sapere <em>quanti<\/em> elementi esistono nei due vettori:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#find how many items exist in both vectors\n<span style=\"color: #000000;\">length(intersect(vector_1, vector_2))\n\n[1] 3<\/span>\n<\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Esistono tre elementi in entrambi i vettori.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Esempio 3: trova elementi che esistono solo in un singolo vettore<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come utilizzare la funzione <strong>setdiff()<\/strong> per visualizzare gli elementi che esistono nel primo vettore, ma non nel secondo:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#definevectors\n<span style=\"color: #000000;\">vector_1 &lt;- c('Andy', 'Bob', 'Carl', 'Doug')\nvector_2 &lt;- c('Bob', 'Carl', 'Doug', 'Ethan', 'Fred')<\/span>\n\n#display items that exist in first vector, but not in second vector<\/span>\nsetdiff(vector_1, vector_2)\n\n[1] \u201cAndy\u201d\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">C&#8217;\u00e8 esattamente un elemento nel primo vettore che non esiste nel secondo vettore.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Possiamo invertire i due vettori per identificare gli elementi che esistono nel secondo vettore, ma non nel primo:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#definevectors\n<span style=\"color: #000000;\">vector_1 &lt;- c('Andy', 'Bob', 'Carl', 'Doug')\nvector_2 &lt;- c('Bob', 'Carl', 'Doug', 'Ethan', 'Fred')<\/span>\n\n#display items that exist in second vector, but not in first vector<\/span>\nsetdiff(vector_2, vector_1)\n\n[1] \u201cEthan\u201d \u201cFred\u201d\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Nel secondo vettore esistono due elementi che non esistono nel primo.<\/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 attivit\u00e0 comuni in R:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/it\/confrontare-due-colonne-in-r\/\" target=\"_blank\" rel=\"noopener\">Come confrontare due colonne in R<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/confrontare-le-stringhe-in-r\/\">Come confrontare le stringhe in R<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/r-aggiungi-al-vettore-in-loop\/\" target=\"_blank\" rel=\"noopener\">Come aggiungere valori a un vettore utilizzando un loop in R<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u00c8 possibile utilizzare la seguente sintassi di base per confrontare due vettori in R: #check if two vectors are identical identical(vector_1, vector_2) #display items that are in both vectors intersect(vector_1, vector_2) #display items that are only in first vector, but not in second vector setdiff(vector_1, vector_2) Gli esempi seguenti mostrano come utilizzare questa sintassi nella [&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 confrontare due vettori in R (con esempi) \u2013 Statorials<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come confrontare due vettori per verificare le differenze 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\/confrontare-due-vettori-in-r\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Come confrontare due vettori in R (con esempi) \u2013 Statorials\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come confrontare due vettori per verificare le differenze in R, con diversi esempi.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/confrontare-due-vettori-in-r\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-24T11:46:40+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\/confrontare-due-vettori-in-r\/\",\"url\":\"https:\/\/statorials.org\/it\/confrontare-due-vettori-in-r\/\",\"name\":\"Come confrontare due vettori in R (con esempi) \u2013 Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-24T11:46:40+00:00\",\"dateModified\":\"2023-07-24T11:46:40+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come confrontare due vettori per verificare le differenze in R, con diversi esempi.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/confrontare-due-vettori-in-r\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/confrontare-due-vettori-in-r\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/confrontare-due-vettori-in-r\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Come confrontare due vettori 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 confrontare due vettori in R (con esempi) \u2013 Statorials","description":"Questo tutorial spiega come confrontare due vettori per verificare le differenze 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\/confrontare-due-vettori-in-r\/","og_locale":"it_IT","og_type":"article","og_title":"Come confrontare due vettori in R (con esempi) \u2013 Statorials","og_description":"Questo tutorial spiega come confrontare due vettori per verificare le differenze in R, con diversi esempi.","og_url":"https:\/\/statorials.org\/it\/confrontare-due-vettori-in-r\/","og_site_name":"Statorials","article_published_time":"2023-07-24T11:46:40+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\/confrontare-due-vettori-in-r\/","url":"https:\/\/statorials.org\/it\/confrontare-due-vettori-in-r\/","name":"Come confrontare due vettori in R (con esempi) \u2013 Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-24T11:46:40+00:00","dateModified":"2023-07-24T11:46:40+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come confrontare due vettori per verificare le differenze in R, con diversi esempi.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/confrontare-due-vettori-in-r\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/confrontare-due-vettori-in-r\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/confrontare-due-vettori-in-r\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Come confrontare due vettori 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\/1914"}],"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=1914"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/1914\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=1914"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=1914"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=1914"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}