{"id":1879,"date":"2023-07-24T15:08:42","date_gmt":"2023-07-24T15:08:42","guid":{"rendered":"https:\/\/statorials.org\/it\/r-valore-mancante-o-vero-falso-necessario\/"},"modified":"2023-07-24T15:08:42","modified_gmt":"2023-07-24T15:08:42","slug":"r-valore-mancante-o-vero-falso-necessario","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/r-valore-mancante-o-vero-falso-necessario\/","title":{"rendered":"Come risolvere in r: valore mancante dove \u00e8 necessario vero\/falso"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Un errore che potresti riscontrare in R \u00e8:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>Error in if (x[i] == NA) {: missing value where TRUE\/FALSE needed\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Questo errore si verifica quando si confronta un valore con NA in un&#8217;istruzione <strong>if<\/strong> in R utilizzando la sintassi <strong>x == NA<\/strong> .<\/span><\/p>\n<p> <span style=\"color: #000000;\">Un&#8217;istruzione <strong>if<\/strong> prevede un valore VERO o FALSO, quindi dovresti utilizzare <strong>is.na(x)<\/strong> perch\u00e9 questa funzione restituisce sempre VERO o FALSO.<\/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 provare a scorrere un elenco di valori in un vettore in R e stampare la parola &#8220;mancante&#8221; ogni volta che \u00e8 presente un valore NA nel vettore:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#define vector with some missing values\n<\/span>x &lt;- c(2, NA, 5, 6, NA, 15, 19)\n\n<span style=\"color: #008080;\">#loop through vector and print \"missing\" each time an NA value is encountered\n<\/span><span style=\"color: #008000;\">for<\/span> (i <span style=\"color: #008000;\">in<\/span> 1:length(x)) {\n \n <span style=\"color: #008000;\">if<\/span> (x[i] == NA) {\n    print(' <span style=\"color: #ff0000;\">Missing<\/span> ')\n  }\n}\n\nError in if (x[i] == NA) {: missing value where TRUE\/FALSE needed\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Riceviamo un errore perch\u00e9 abbiamo utilizzato la sintassi <strong>x[i] == NA<\/strong> .<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Come correggere l&#8217;errore<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Dobbiamo cambiare la sintassi in <strong>is.na(x)<\/strong> come segue:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#define vector with some missing values\n<\/span>x &lt;- c(2, NA, 5, 6, NA, 15, 19)\n\n<span style=\"color: #008080;\">#loop through vector and print \"missing\" each time an NA value is encountered\n<\/span><span style=\"color: #008000;\">for<\/span> (i <span style=\"color: #008000;\">in<\/span> 1:length(x)) {\n \n <span style=\"color: #008000;\">if<\/span> (is. <span style=\"color: #3366ff;\">na<\/span> (x[i])) {\n    print(' <span style=\"color: #ff0000;\">Missing<\/span> ')\n  }\n}\n\n[1] \u201cMissing\u201d\n[1] \u201cMissing\u201d\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Tieni presente che non riceviamo un errore e possiamo stampare la parola &#8220;mancante&#8221; ogni volta che incontriamo un valore NA nel vettore.<\/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\/nas-introdotto-con-la-coercizione-in-r\/\" target=\"_blank\" rel=\"noopener\">Come risolvere: NA introdotte dalla coercizione<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/r-numero-errato-di-indici-sulla-matrice\/\" target=\"_blank\" rel=\"noopener\">Come risolvere il problema: numero errato di indici sulla matrice<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/r-numero-di-articoli-da-sostituire-non-multiplo-della-lunghezza-di-sostituzione\/\" target=\"_blank\" rel=\"noopener\">Modalit\u00e0 di riparazione: il numero di pezzi da sostituire non \u00e8 multiplo della lunghezza di sostituzione<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Un errore che potresti riscontrare in R \u00e8: Error in if (x[i] == NA) {: missing value where TRUE\/FALSE needed Questo errore si verifica quando si confronta un valore con NA in un&#8217;istruzione if in R utilizzando la sintassi x == NA . Un&#8217;istruzione if prevede un valore VERO o FALSO, quindi dovresti utilizzare is.na(x) [&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: valore mancante dove \u00e8 necessario vero\/falso<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come risolvere il seguente errore in R: valore mancante dove \u00e8 necessario vero\/falso.\" \/>\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-valore-mancante-o-vero-falso-necessario\/\" \/>\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: valore mancante dove \u00e8 necessario vero\/falso\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come risolvere il seguente errore in R: valore mancante dove \u00e8 necessario vero\/falso.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/r-valore-mancante-o-vero-falso-necessario\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-24T15:08:42+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=\"1 minuto\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/it\/r-valore-mancante-o-vero-falso-necessario\/\",\"url\":\"https:\/\/statorials.org\/it\/r-valore-mancante-o-vero-falso-necessario\/\",\"name\":\"Come risolvere in R: valore mancante dove \u00e8 necessario vero\/falso\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-24T15:08:42+00:00\",\"dateModified\":\"2023-07-24T15:08:42+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come risolvere il seguente errore in R: valore mancante dove \u00e8 necessario vero\/falso.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/r-valore-mancante-o-vero-falso-necessario\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/r-valore-mancante-o-vero-falso-necessario\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/r-valore-mancante-o-vero-falso-necessario\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Come risolvere in r: valore mancante dove \u00e8 necessario vero\/falso\"}]},{\"@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: valore mancante dove \u00e8 necessario vero\/falso","description":"Questo tutorial spiega come risolvere il seguente errore in R: valore mancante dove \u00e8 necessario vero\/falso.","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-valore-mancante-o-vero-falso-necessario\/","og_locale":"it_IT","og_type":"article","og_title":"Come risolvere in R: valore mancante dove \u00e8 necessario vero\/falso","og_description":"Questo tutorial spiega come risolvere il seguente errore in R: valore mancante dove \u00e8 necessario vero\/falso.","og_url":"https:\/\/statorials.org\/it\/r-valore-mancante-o-vero-falso-necessario\/","og_site_name":"Statorials","article_published_time":"2023-07-24T15:08:42+00:00","author":"Benjamin anderson","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Benjamin anderson","Est. reading time":"1 minuto"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/it\/r-valore-mancante-o-vero-falso-necessario\/","url":"https:\/\/statorials.org\/it\/r-valore-mancante-o-vero-falso-necessario\/","name":"Come risolvere in R: valore mancante dove \u00e8 necessario vero\/falso","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-24T15:08:42+00:00","dateModified":"2023-07-24T15:08:42+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come risolvere il seguente errore in R: valore mancante dove \u00e8 necessario vero\/falso.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/r-valore-mancante-o-vero-falso-necessario\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/r-valore-mancante-o-vero-falso-necessario\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/r-valore-mancante-o-vero-falso-necessario\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Come risolvere in r: valore mancante dove \u00e8 necessario vero\/falso"}]},{"@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\/1879"}],"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=1879"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/1879\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=1879"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=1879"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=1879"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}