{"id":3057,"date":"2023-07-19T10:27:35","date_gmt":"2023-07-19T10:27:35","guid":{"rendered":"https:\/\/statorials.org\/it\/largomento-r-ha-lunghezza-zero\/"},"modified":"2023-07-19T10:27:35","modified_gmt":"2023-07-19T10:27:35","slug":"largomento-r-ha-lunghezza-zero","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/largomento-r-ha-lunghezza-zero\/","title":{"rendered":"Come risolvere in r: l&#39;argomento ha lunghezza zero"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Un messaggio di errore che potresti riscontrare quando usi R \u00e8:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>Error in if (x &lt; 10) {: argument is of length zero\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Questo errore si verifica in genere quando si tenta di eseguire un confronto logico in un&#8217;istruzione if in R, ma la variabile utilizzata nel confronto ha lunghezza zero.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Due esempi di variabili di lunghezza zero sono <strong>numeric()<\/strong> o <strong>Character(0)<\/strong> .<\/span><\/p>\n<p> <span style=\"color: #000000;\">L&#8217;esempio seguente mostra come risolvere questo errore nella pratica.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Come riprodurre l&#8217;errore<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Supponiamo di creare la seguente variabile numerica in R con lunghezza zero:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#create numeric variable with length of zero\n<span style=\"color: #000000;\">x &lt;- numeric()<\/span>\n<\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Supponiamo ora di provare a utilizzare questa variabile in<\/span> <span style=\"color: #000000;\">un&#8217;istruzione if:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#if x is less than 10, print x to console\n<span style=\"color: #000000;\">if(x &lt; <span style=\"color: #008000;\">10<\/span> ) {\n  x\n}\n\nError in if (x &lt; 10) {: argument is of length zero\n<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Riceviamo un errore perch\u00e9 la variabile che definiamo ha lunghezza zero.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Se creassimo semplicemente una variabile numerica con un valore reale, non riceveremmo mai questo errore quando utilizziamo l&#8217;istruzione if:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#create numeric variable\n<span style=\"color: #000000;\">y &lt;- 5<\/span>\n\n#if y is less than 10, print y to console\n<span style=\"color: #000000;\">if(y &lt; <span style=\"color: #008000;\">10<\/span> ) {\n  y\n}\n\n[1] 5\n<\/span><\/span><\/strong><\/pre>\n<h3> <span style=\"color: #000000;\"><strong>Come evitare l&#8217;errore<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Per evitare l&#8217;errore <strong>di lunghezza dell&#8217;argomento pari a zero<\/strong> , dobbiamo includere una funzione <strong>isTRUE<\/strong> , che utilizza la seguente logica:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\">is. <span style=\"color: #3366ff;\">logical<\/span> (x) &amp;&amp; length(x) == <span style=\"color: #008000;\">1<\/span> &amp;&amp; !is. <span style=\"color: #3366ff;\">na<\/span> (x) &amp;&amp; x<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Se usiamo questa funzione nell&#8217;istruzione if, non riceveremo un errore quando confrontiamo la nostra variabile con un valore:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\">if(isTRUE(x) &amp;&amp; x &lt; <span style=\"color: #008000;\">10<\/span> ) {\n  x\n}\n<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Invece di ricevere un errore, semplicemente non riceviamo alcun output perch\u00e9 la funzione <strong>isTRUE(x)<\/strong> restituisce <strong>FALSE<\/strong> , il che significa che il valore di x non viene mai stampato.<\/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 correggere altri errori comuni in R:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/it\/gli-argomenti-r-implicano-un-numero-diverso-di-righe\/\" target=\"_blank\" rel=\"noopener\">Come risolvere in R: gli argomenti coinvolgono un numero diverso di righe<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/errore-dplyr-nella-selezione-degli-argomenti-inutilizzati\/\" target=\"_blank\" rel=\"noopener\">Come risolvere in R: errore nella selezione di argomenti inutilizzati<\/a><br \/><a href=\"https:\/\/statorials.org\/it\/r-sostituzione-a-lunghezza-zero\/\" target=\"_blank\" rel=\"noopener\">Come riparare in R: la sostituzione ha lunghezza zero<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Un messaggio di errore che potresti riscontrare quando usi R \u00e8: Error in if (x &lt; 10) {: argument is of length zero Questo errore si verifica in genere quando si tenta di eseguire un confronto logico in un&#8217;istruzione if in R, ma la variabile utilizzata nel confronto ha lunghezza zero. Due esempi di variabili [&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 risolvere in R: l&#039;argomento ha lunghezza zero - Statorials<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come correggere l&#039;errore &quot;L&#039;argomento ha lunghezza zero&quot; in R, inclusi 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\/largomento-r-ha-lunghezza-zero\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Come risolvere in R: l&#039;argomento ha lunghezza zero - Statorials\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come correggere l&#039;errore &quot;L&#039;argomento ha lunghezza zero&quot; in R, inclusi esempi.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/largomento-r-ha-lunghezza-zero\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-19T10:27:35+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\/largomento-r-ha-lunghezza-zero\/\",\"url\":\"https:\/\/statorials.org\/it\/largomento-r-ha-lunghezza-zero\/\",\"name\":\"Come risolvere in R: l&#39;argomento ha lunghezza zero - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-19T10:27:35+00:00\",\"dateModified\":\"2023-07-19T10:27:35+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come correggere l&#39;errore &quot;L&#39;argomento ha lunghezza zero&quot; in R, inclusi esempi.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/largomento-r-ha-lunghezza-zero\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/largomento-r-ha-lunghezza-zero\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/largomento-r-ha-lunghezza-zero\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Come risolvere in r: l&#39;argomento ha lunghezza zero\"}]},{\"@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 risolvere in R: l&#39;argomento ha lunghezza zero - Statorials","description":"Questo tutorial spiega come correggere l&#39;errore &quot;L&#39;argomento ha lunghezza zero&quot; in R, inclusi 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\/largomento-r-ha-lunghezza-zero\/","og_locale":"it_IT","og_type":"article","og_title":"Come risolvere in R: l&#39;argomento ha lunghezza zero - Statorials","og_description":"Questo tutorial spiega come correggere l&#39;errore &quot;L&#39;argomento ha lunghezza zero&quot; in R, inclusi esempi.","og_url":"https:\/\/statorials.org\/it\/largomento-r-ha-lunghezza-zero\/","og_site_name":"Statorials","article_published_time":"2023-07-19T10:27:35+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\/largomento-r-ha-lunghezza-zero\/","url":"https:\/\/statorials.org\/it\/largomento-r-ha-lunghezza-zero\/","name":"Come risolvere in R: l&#39;argomento ha lunghezza zero - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-19T10:27:35+00:00","dateModified":"2023-07-19T10:27:35+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come correggere l&#39;errore &quot;L&#39;argomento ha lunghezza zero&quot; in R, inclusi esempi.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/largomento-r-ha-lunghezza-zero\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/largomento-r-ha-lunghezza-zero\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/largomento-r-ha-lunghezza-zero\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Come risolvere in r: l&#39;argomento ha lunghezza zero"}]},{"@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\/3057"}],"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=3057"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/3057\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=3057"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=3057"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=3057"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}