{"id":4112,"date":"2023-07-13T12:49:50","date_gmt":"2023-07-13T12:49:50","guid":{"rendered":"https:\/\/statorials.org\/it\/r-leggi-righe-specifiche-csv\/"},"modified":"2023-07-13T12:49:50","modified_gmt":"2023-07-13T12:49:50","slug":"r-leggi-righe-specifiche-csv","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/r-leggi-righe-specifiche-csv\/","title":{"rendered":"Come leggere righe specifiche da un file csv in r"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">\u00c8 possibile utilizzare i seguenti metodi per leggere righe specifiche da un file CSV in R:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Metodo 1: importa un file CSV da una riga specifica<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>df &lt;- read. <span style=\"color: #3366ff;\">csv<\/span> (\" <span style=\"color: #ff0000;\">my_data.csv<\/span> \", skip= <span style=\"color: #008000;\">2<\/span> )\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Questo particolare esempio salter\u00e0 le prime due righe del file CSV e importer\u00e0 tutte le altre righe del file a partire dalla terza riga.<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Metodo 2: importa un file CSV in cui le righe soddisfano la condizione<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\">library<\/span> (sqldf)\n\ndf &lt;- read. <span style=\"color: #3366ff;\">csv<\/span> . <span style=\"color: #3366ff;\">sql<\/span> (\" <span style=\"color: #ff0000;\">my_data.csv<\/span> \",\n                    sql = \" <span style=\"color: #ff0000;\">select * from file where `points` &gt; 90<\/span> \", eol = \" <span style=\"color: #ff0000;\">\\n<\/span> \")\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Questo particolare esempio importer\u00e0 solo le righe dal file CSV il cui valore nella colonna &#8220;punti&#8221; \u00e8 maggiore di 90.<\/span><\/p>\n<p> <span style=\"color: #000000;\">I seguenti esempi mostrano come utilizzare nella pratica ciascuno di questi metodi con il seguente file CSV chiamato <strong>my_data.csv<\/strong> :<\/span> <\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-32661 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/certain1.png\" alt=\"\" width=\"542\" height=\"414\" srcset=\"\" sizes=\"\"><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Esempio 1: importa un file CSV da una riga specifica<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come importare il file CSV e ignorare le prime due righe del file:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008080;\">#import data frame and skip first two rows\n<\/span>df &lt;- read. <span style=\"color: #3366ff;\">csv<\/span> (' <span style=\"color: #ff0000;\">my_data.csv<\/span> ', skip= <span style=\"color: #008000;\">2<\/span> )\n\n<span style=\"color: #008080;\">#view data frame\n<\/span>df\n\n  B X90 X28 X28.1\n1 C 86 31 24\n2 D 88 39 24\n3 E 95 34 28<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Tieni presente che le prime due righe (con le squadre A e B) sono state ignorate durante l&#8217;importazione del file CSV.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Per impostazione predefinita, R tenta di utilizzare i valori della successiva riga disponibile come nomi di colonna.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Per rinominare le colonne, puoi utilizzare la <strong>funzionenames()<\/strong> come segue:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008080;\">#rename columns\n<\/span>names(df) &lt;- c(' <span style=\"color: #ff0000;\">team<\/span> ', ' <span style=\"color: #ff0000;\">points<\/span> ', ' <span style=\"color: #ff0000;\">assists<\/span> ', ' <span style=\"color: #ff0000;\">rebounds<\/span> ')\n\n<span style=\"color: #008080;\">#view updated data frame<\/span>\ndf\n\n  team points assists rebounds\n1 C 86 31 24\n2 D 88 39 24\n3 E 95 34 28\n<\/span><\/span><\/strong><\/pre>\n<h2> <span style=\"color: #000000;\"><strong>Esempio 2: importa un file CSV in cui le righe soddisfano la condizione<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Supponiamo di voler importare solo quelle righe dal file CSV il cui valore nella colonna punti \u00e8 maggiore di 90.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Possiamo usare la funzione <strong>read.csv.sql<\/strong> dal pacchetto <strong>sqldf<\/strong> per fare questo:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #008000;\">library<\/span> (sqldf)\n\n<span style=\"color: #008080;\">#only import rows where points &gt; 90\n<\/span>df &lt;- read. <span style=\"color: #3366ff;\">csv<\/span> . <span style=\"color: #3366ff;\">sql<\/span> (\" <span style=\"color: #ff0000;\">my_data.csv<\/span> \",\n                    sql = \" <span style=\"color: #ff0000;\">select * from file where `points` &gt; 90<\/span> \", eol = \" <span style=\"color: #ff0000;\">\\n<\/span> \")\n\n<span style=\"color: #008080;\">#view data frame\n<\/span>df\n\n  team points assists rebounds\n1 \u201cA\u201d 99 33 30\n2 \u201cE\u201d 95 34 28\n<\/strong><\/span><\/pre>\n<p> <span style=\"color: #000000;\">Da notare che sono state importate solo le due righe del file CSV il cui valore nella colonna \u201cpunti\u201d \u00e8 maggiore di 90.<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Nota n. 1<\/strong> : in questo esempio, abbiamo utilizzato l&#8217;argomento <strong>eol<\/strong> per specificare che la &#8220;fine riga&#8221; nel file \u00e8 indicata da <strong>\\n<\/strong> , che rappresenta una nuova riga.<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Nota n.2:<\/strong> in questo esempio abbiamo utilizzato una semplice query SQL, ma puoi scrivere query pi\u00f9 complesse per filtrare le righe in base a un numero ancora maggiore di condizioni.<\/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\/r-leggi-csv-da-lurl\/\">Come leggere un CSV da un URL in R<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/r-unisci-file-csv\/\" target=\"_blank\" rel=\"noopener\">Come unire pi\u00f9 file CSV in R<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/esporta-il-frame-di-dati-in-csv-in-r\/\" target=\"_blank\" rel=\"noopener\">Come esportare un frame di dati in un file CSV in R<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u00c8 possibile utilizzare i seguenti metodi per leggere righe specifiche da un file CSV in R: Metodo 1: importa un file CSV da una riga specifica df &lt;- read. csv (&#8221; my_data.csv &#8220;, skip= 2 ) Questo particolare esempio salter\u00e0 le prime due righe del file CSV e importer\u00e0 tutte le altre righe del file [&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 leggere righe specifiche da un file CSV in R - Statorials<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come leggere solo righe specifiche da un file CSV in R, con un esempio.\" \/>\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-leggi-righe-specifiche-csv\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Come leggere righe specifiche da un file CSV in R - Statorials\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come leggere solo righe specifiche da un file CSV in R, con un esempio.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/r-leggi-righe-specifiche-csv\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-13T12:49:50+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/certain1.png\" \/>\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-leggi-righe-specifiche-csv\/\",\"url\":\"https:\/\/statorials.org\/it\/r-leggi-righe-specifiche-csv\/\",\"name\":\"Come leggere righe specifiche da un file CSV in R - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-13T12:49:50+00:00\",\"dateModified\":\"2023-07-13T12:49:50+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come leggere solo righe specifiche da un file CSV in R, con un esempio.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/r-leggi-righe-specifiche-csv\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/r-leggi-righe-specifiche-csv\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/r-leggi-righe-specifiche-csv\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Come leggere righe specifiche da un file csv 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 leggere righe specifiche da un file CSV in R - Statorials","description":"Questo tutorial spiega come leggere solo righe specifiche da un file CSV in R, con un esempio.","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-leggi-righe-specifiche-csv\/","og_locale":"it_IT","og_type":"article","og_title":"Come leggere righe specifiche da un file CSV in R - Statorials","og_description":"Questo tutorial spiega come leggere solo righe specifiche da un file CSV in R, con un esempio.","og_url":"https:\/\/statorials.org\/it\/r-leggi-righe-specifiche-csv\/","og_site_name":"Statorials","article_published_time":"2023-07-13T12:49:50+00:00","og_image":[{"url":"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/certain1.png"}],"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-leggi-righe-specifiche-csv\/","url":"https:\/\/statorials.org\/it\/r-leggi-righe-specifiche-csv\/","name":"Come leggere righe specifiche da un file CSV in R - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-13T12:49:50+00:00","dateModified":"2023-07-13T12:49:50+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come leggere solo righe specifiche da un file CSV in R, con un esempio.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/r-leggi-righe-specifiche-csv\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/r-leggi-righe-specifiche-csv\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/r-leggi-righe-specifiche-csv\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Come leggere righe specifiche da un file csv 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\/4112"}],"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=4112"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/4112\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=4112"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=4112"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=4112"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}