{"id":3475,"date":"2023-07-17T07:23:06","date_gmt":"2023-07-17T07:23:06","guid":{"rendered":"https:\/\/statorials.org\/it\/r-singole-righe\/"},"modified":"2023-07-17T07:23:06","modified_gmt":"2023-07-17T07:23:06","slug":"r-singole-righe","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/r-singole-righe\/","title":{"rendered":"Come selezionare singole righe in un frame di dati in r"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">\u00c8 possibile utilizzare i seguenti metodi per selezionare singole righe in un frame di dati in R:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Metodo 1: seleziona singole righe in tutte le colonne<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\">library<\/span> (dplyr)\n\ndf %&gt;% distinct()<\/strong><\/pre>\n<p> <span style=\"color: #000000;\"><strong>Metodo 2: selezionare singole righe in base a una colonna<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\"><span style=\"color: #000000;\"><span style=\"color: #008000;\">library<\/span> (dplyr)<\/span>\n\n<span style=\"color: #000000;\">df %&gt;% distinct(column1, . <span style=\"color: #3366ff;\">keep_all<\/span> = <span style=\"color: #008000;\">TRUE<\/span> )<\/span>\n<\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\"><strong>Metodo 3: selezionare singole righe in base a pi\u00f9 colonne<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\"><span style=\"color: #000000;\"><span style=\"color: #008000;\">library<\/span> (dplyr)\n\ndf %&gt;% distinct(column1, column2, . <span style=\"color: #3366ff;\">keep_all<\/span> = <span style=\"color: #008000;\">TRUE<\/span> )<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Questo tutorial spiega come utilizzare ciascun metodo nella pratica con il seguente frame di dati:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #008080;\">#create data frame\n<span style=\"color: #000000;\">df &lt;- data. <span style=\"color: #3366ff;\">frame<\/span> (team=c('A', 'A', 'A', 'A', 'B', 'B', 'B', 'B'),\n                 position=c('G', 'G', 'F', 'F', 'G', 'G', 'F', 'F'),\n                 points=c(10, 10, 8, 14, 15, 15, 17, 17))\n<\/span>\n#view data frame\n<span style=\"color: #000000;\">df\n\n  team position points\n1 AG 10\n2 AG 10\n3AF 8\n4 AF 14\n5 BG 15\n6 BG 15\n7 BF 17\n8 BF 17\n<\/span><\/span><\/strong><\/span><\/pre>\n<h2> <span style=\"color: #000000;\"><strong>Esempio 1: seleziona righe univoche in tutte le colonne<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come selezionare righe con valori univoci su tutte le colonne nel frame di dati:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008000;\">library<\/span> (dplyr)<\/span>\n\n#select rows with unique values across all columns\n<span style=\"color: #000000;\">df %&gt;% distinct()\n\n  team position points\n1 AG 10\n2AF 8\n3 AF 14\n4 BG 15\n5 BF 17\n<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Possiamo vedere che ci sono cinque righe uniche nel frame di dati.<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Nota<\/strong> : quando vengono rilevate righe duplicate, viene conservata solo la prima riga univoca.<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Esempio 2: selezionare righe singole in base a una colonna<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come selezionare righe singole in base solo alla colonna <strong>del team<\/strong> .<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #008000;\">library<\/span> (dplyr)\n\n<span style=\"color: #008080;\">#select rows with unique values based on team column only<\/span>\ndf %&gt;% distinct(team, . <span style=\"color: #3366ff;\">keep_all<\/span> = <span style=\"color: #008000;\">TRUE<\/span> )\n\n  team position points\n1 AG 10\n2 BG 15\n<\/strong><\/span><\/pre>\n<p> <span style=\"color: #000000;\"><span style=\"color: #000000;\">Poich\u00e9 nella colonna <strong>Team<\/strong> sono presenti solo due valori univoci, vengono mantenute solo le righe con la prima occorrenza di ciascun valore.<\/span><\/span><\/p>\n<p> <span style=\"color: #000000;\"><span style=\"color: #000000;\"><strong>Nota<\/strong> : l&#8217;argomento <strong>.keep_all=TRUE<\/strong> indica a R di mantenere tutte le altre colonne nell&#8217;output.<\/span><\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Esempio 3: selezionare singole righe in base a pi\u00f9 colonne<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come selezionare singole righe in base solo alle colonne <strong>della squadra<\/strong> e <strong>della posizione<\/strong> .<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #008000;\">library<\/span> (dplyr)\n\n<span style=\"color: #008080;\">#select rows with unique values based on team and position columns only<\/span>\ndf %&gt;% distinct(team, position, . <span style=\"color: #3366ff;\">keep_all<\/span> = <span style=\"color: #008000;\">TRUE<\/span> )\n\n  team position points\n1 AG 10\n2AF 8\n3 BG 15\n4 BF 17\n<\/strong><\/span><\/pre>\n<p> <span style=\"color: #000000;\"><span style=\"color: #000000;\">Vengono restituite quattro righe perch\u00e9 sono presenti quattro combinazioni univoche di valori nelle colonne <strong>Squadra<\/strong> e <strong>Posizione<\/strong> .<\/span><\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Risorse addizionali<\/strong><\/span><\/h2>\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\/filtro-a-doppia-matrice\/\" target=\"_blank\" rel=\"noopener\">Come filtrare valori univoci utilizzando dplyr<\/a><br \/> Come filtrare in base a pi\u00f9 condizioni utilizzando dplyr<br \/> <a href=\"https:\/\/statorials.org\/it\/r-conta-il-numero-di-occorrenze-nella-colonna\/\" target=\"_blank\" rel=\"noopener\">Come contare il numero di occorrenze nelle colonne in R<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u00c8 possibile utilizzare i seguenti metodi per selezionare singole righe in un frame di dati in R: Metodo 1: seleziona singole righe in tutte le colonne library (dplyr) df %&gt;% distinct() Metodo 2: selezionare singole righe in base a una colonna library (dplyr) df %&gt;% distinct(column1, . keep_all = TRUE ) Metodo 3: selezionare singole [&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 selezionare singole righe in un frame di dati in R - Stology<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come selezionare singole righe da un frame di dati 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\/r-singole-righe\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Come selezionare singole righe in un frame di dati in R - Stology\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come selezionare singole righe da un frame di dati in R, con diversi esempi.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/r-singole-righe\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-17T07:23:06+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\/r-singole-righe\/\",\"url\":\"https:\/\/statorials.org\/it\/r-singole-righe\/\",\"name\":\"Come selezionare singole righe in un frame di dati in R - Stology\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-17T07:23:06+00:00\",\"dateModified\":\"2023-07-17T07:23:06+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come selezionare singole righe da un frame di dati in R, con diversi esempi.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/r-singole-righe\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/r-singole-righe\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/r-singole-righe\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Come selezionare singole righe in un frame di dati in r\"}]},{\"@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 selezionare singole righe in un frame di dati in R - Stology","description":"Questo tutorial spiega come selezionare singole righe da un frame di dati 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\/r-singole-righe\/","og_locale":"it_IT","og_type":"article","og_title":"Come selezionare singole righe in un frame di dati in R - Stology","og_description":"Questo tutorial spiega come selezionare singole righe da un frame di dati in R, con diversi esempi.","og_url":"https:\/\/statorials.org\/it\/r-singole-righe\/","og_site_name":"Statorials","article_published_time":"2023-07-17T07:23:06+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\/r-singole-righe\/","url":"https:\/\/statorials.org\/it\/r-singole-righe\/","name":"Come selezionare singole righe in un frame di dati in R - Stology","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-17T07:23:06+00:00","dateModified":"2023-07-17T07:23:06+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come selezionare singole righe da un frame di dati in R, con diversi esempi.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/r-singole-righe\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/r-singole-righe\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/r-singole-righe\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Come selezionare singole righe in un frame di dati in r"}]},{"@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\/3475"}],"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=3475"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/3475\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=3475"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=3475"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=3475"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}