{"id":1913,"date":"2023-07-24T11:50:10","date_gmt":"2023-07-24T11:50:10","guid":{"rendered":"https:\/\/statorials.org\/it\/x-deve-essere-numerico\/"},"modified":"2023-07-24T11:50:10","modified_gmt":"2023-07-24T11:50:10","slug":"x-deve-essere-numerico","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/x-deve-essere-numerico\/","title":{"rendered":"Come risolvere in r: &#39;x&#39; deve essere numerico"},"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 hist.default(data): 'x' must be numeric\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Questo errore si verifica quando si tenta di creare un istogramma per una variabile non numerica.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Questo tutorial spiega esattamente come correggere questo errore.<\/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 creare un istogramma per il seguente vettore di dati:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#definevector\n<\/span>data &lt;- c('1.2', '1.4', '1.7', '1.9', '2.2', '2.5', '3', '3.4', '3.7', '4.1')\n\n<span style=\"color: #008080;\">#attempt to create histogram to visualize distribution of values in vector\n<\/span>hist(data)\n\nError in hist.default(data): 'x' must be numeric\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Stiamo ricevendo un errore perch\u00e9 <strong>i dati<\/strong> attualmente non sono un vettore numerico. Possiamo confermarlo controllando la classe:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#check class\n<\/span>class(data)\n\n[1] \u201ccharacter\u201d\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Attualmente <strong>i dati<\/strong> sono un vettore di caratteri.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Come correggere l&#8217;errore<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Il modo pi\u00f9 semplice per correggere questo errore \u00e8 utilizzare semplicemente <strong>as.numeric()<\/strong> per convertire il nostro vettore in numerico:<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#convert vector from character to numeric\n<\/span>data_numeric &lt;- as. <span style=\"color: #3366ff;\">numeric<\/span> (data)\n\n<span style=\"color: #008080;\">#create histogram\n<span style=\"color: #000000;\">hist(data_numeric)<\/span><\/span>\n<\/strong><\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-18279 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/histr1.png\" alt=\"\" width=\"429\" height=\"429\" srcset=\"\" sizes=\"\"><\/p>\n<p> <span style=\"color: #000000;\">Tieni presente che non riceviamo un errore e siamo in grado di creare l&#8217;istogramma perch\u00e9 il nostro vettore ora \u00e8 numerico.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Possiamo verificarlo controllando la classe:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#check class\n<\/span>class(data_numeric)\n\n[1] \"digital\"\n<\/strong><\/pre>\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\">Come risolvere il problema: il numero di articoli 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 hist.default(data): &#8216;x&#8217; must be numeric Questo errore si verifica quando si tenta di creare un istogramma per una variabile non numerica. Questo tutorial spiega esattamente come correggere questo errore. Come riprodurre l&#8217;errore Supponiamo di provare a creare un istogramma per il seguente vettore di dati: [&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: &#039;x&#039; deve essere numerico - Statorials<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come correggere il seguente errore in R: &quot;x&quot; deve essere numerico.\" \/>\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\/x-deve-essere-numerico\/\" \/>\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: &#039;x&#039; deve essere numerico - Statorials\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come correggere il seguente errore in R: &quot;x&quot; deve essere numerico.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/x-deve-essere-numerico\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-24T11:50:10+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/histr1.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=\"1 minuto\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/it\/x-deve-essere-numerico\/\",\"url\":\"https:\/\/statorials.org\/it\/x-deve-essere-numerico\/\",\"name\":\"Come risolvere in R: &#39;x&#39; deve essere numerico - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-24T11:50:10+00:00\",\"dateModified\":\"2023-07-24T11:50:10+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come correggere il seguente errore in R: &quot;x&quot; deve essere numerico.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/x-deve-essere-numerico\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/x-deve-essere-numerico\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/x-deve-essere-numerico\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Come risolvere in r: &#39;x&#39; deve essere numerico\"}]},{\"@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: &#39;x&#39; deve essere numerico - Statorials","description":"Questo tutorial spiega come correggere il seguente errore in R: &quot;x&quot; deve essere numerico.","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\/x-deve-essere-numerico\/","og_locale":"it_IT","og_type":"article","og_title":"Come risolvere in R: &#39;x&#39; deve essere numerico - Statorials","og_description":"Questo tutorial spiega come correggere il seguente errore in R: &quot;x&quot; deve essere numerico.","og_url":"https:\/\/statorials.org\/it\/x-deve-essere-numerico\/","og_site_name":"Statorials","article_published_time":"2023-07-24T11:50:10+00:00","og_image":[{"url":"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/histr1.png"}],"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\/x-deve-essere-numerico\/","url":"https:\/\/statorials.org\/it\/x-deve-essere-numerico\/","name":"Come risolvere in R: &#39;x&#39; deve essere numerico - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-24T11:50:10+00:00","dateModified":"2023-07-24T11:50:10+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come correggere il seguente errore in R: &quot;x&quot; deve essere numerico.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/x-deve-essere-numerico\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/x-deve-essere-numerico\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/x-deve-essere-numerico\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Come risolvere in r: &#39;x&#39; deve essere numerico"}]},{"@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\/1913"}],"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=1913"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/1913\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=1913"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=1913"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=1913"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}