{"id":1848,"date":"2023-07-24T18:20:52","date_gmt":"2023-07-24T18:20:52","guid":{"rendered":"https:\/\/statorials.org\/it\/errore-in-do_onenmeth-na-nan-inf-nella-chiamata-di-funzione-esterna\/"},"modified":"2023-07-24T18:20:52","modified_gmt":"2023-07-24T18:20:52","slug":"errore-in-do_onenmeth-na-nan-inf-nella-chiamata-di-funzione-esterna","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/errore-in-do_onenmeth-na-nan-inf-nella-chiamata-di-funzione-esterna\/","title":{"rendered":"Come risolvere: errore in do_one(nmeth): na\/nan\/inf nella chiamata di funzione esterna (arg 1)"},"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 do_one(nmeth): NA\/NaN\/Inf in foreign function call (arg 1)\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Questo errore si verifica quando si tenta di eseguire<a href=\"https:\/\/statorials.org\/it\/k-significa-raggruppamento-in-r\/\" target=\"_blank\" rel=\"noopener\">il clustering k-means in R<\/a> ma il frame di dati in uso presenta uno o pi\u00f9 valori mancanti.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Questo tutorial spiega esattamente come correggere questo errore.<\/span><\/p>\n<h3> <strong>Come riprodurre l&#8217;errore<\/strong><\/h3>\n<p> <span style=\"color: #000000;\">Supponiamo di avere il seguente frame di dati in R con un valore mancante nella seconda riga:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#create data frame\n<\/span>df &lt;- data. <span style=\"color: #3366ff;\">frame<\/span> (var1=c(2, 4, 4, 6, 7, 8, 8, 9, 9, 12),\n                 var2=c(12, 14, 14, 8, 8, 15, 16, 9, 9, 11),\n                 var3=c(22, NA, 23, 24, 28, 23, 19, 16, 12, 15))\n\nrow. <span style=\"color: #3366ff;\">names<\/span> (df) &lt;- LETTERS[1:10]\n\n<span style=\"color: #008080;\">#view data frame\n<\/span>df\n\n  var1 var2 var3\nAt 2 12 22\nB 4 14 NA\nC 4 14 23\nD 6 8 24\nE 7 8 28\nF 8 15 23\nG 8 16 19\nH 9 9 16\nI 9 9 12\nD 12 11 15<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Se proviamo a utilizzare la funzione <strong>kmeans()<\/strong> per eseguire il clustering k-means su questo frame di dati, riceveremo un errore:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#attempt to perform k-means clustering with k = 3 clusters\n<\/span>km &lt;- kmeans(df, centers = <span style=\"color: #008000;\">3<\/span> )\n\nError in do_one(nmeth): NA\/NaN\/Inf in foreign function call (arg 1)\n<\/strong><\/pre>\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 la funzione <a href=\"https:\/\/statorials.org\/it\/na-omettere-nella-r\/\" target=\"_blank\" rel=\"noopener\">na.omit()<\/a> per rimuovere le righe con valori mancanti dal frame di dati:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#remove rows with NA values\n<\/span>df &lt;- na. <span style=\"color: #3366ff;\">omitted<\/span> (df)\n\n<span style=\"color: #008080;\">#perform k-means clustering with k = 3 clusters\n<\/span>km &lt;- kmeans(df, centers = 3)\n\n<span style=\"color: #008080;\">#view results\n<\/span>km\n\nK-means clustering with 3 clusters of sizes 4, 3, 2\n\nCluster means:\n  var1 var2 var3\n1 5.5 14.250000 21.75000\n2 10.0 9.666667 14.33333\n3 6.5 8.000000 26.00000\n\nVector clustering:\nACDEFGHIJ\n1 1 3 3 1 1 2 2 2 \n\nWithin cluster sum of squares by cluster:\n[1] 46.50000 17.33333 8.50000\n (between_SS \/ total_SS = 79.5%)\n\nAvailable components:\n\n[1] \"cluster\" \"centers\" \"totss\" \"withinss\" \"tot.withinss\"\n[6] \"betweenss\" \"size\" \"iter\" \"ifault\"<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Tieni presente che l&#8217;algoritmo di clustering k-means viene eseguito correttamente una volta rimosse le righe con valori mancanti dal frame di dati.<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Bonus:<\/strong><a href=\"https:\/\/statorials.org\/it\/k-significa-raggruppamento-in-r\/\" target=\"_blank\" rel=\"noopener\">una guida passo passo completa al clustering k-means in R<\/a><\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Risorse addizionali<\/strong><\/span><\/h3>\n<p> <a href=\"https:\/\/statorials.org\/it\/nas-introdotto-con-la-coercizione-in-r\/\" target=\"_blank\" rel=\"noopener\">Come risolvere in R: NA introdotte dalla coercizione<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/r-indice-di-errore-fuori-range\/\" target=\"_blank\" rel=\"noopener\">Come riparare in R: indice fuori limite<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\" target=\"_blank\" rel=\"noopener\">Come risolvere in R: la lunghezza di un oggetto pi\u00f9 lungo non \u00e8 un multiplo della lunghezza di un oggetto pi\u00f9 corto<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Un errore che potresti riscontrare in R \u00e8: Error in do_one(nmeth): NA\/NaN\/Inf in foreign function call (arg 1) Questo errore si verifica quando si tenta di eseguireil clustering k-means in R ma il frame di dati in uso presenta uno o pi\u00f9 valori mancanti. Questo tutorial spiega esattamente come correggere questo errore. Come riprodurre l&#8217;errore [&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: errore in do_one(nmeth): na\/nan\/inf nella chiamata di funzione esterna (arg 1)<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come correggere il seguente errore in R: errore in do_one(nmeth): na\/nan\/inf nella chiamata di funzione esterna (arg 1).\" \/>\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\/errore-in-do_onenmeth-na-nan-inf-nella-chiamata-di-funzione-esterna\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Come risolvere: errore in do_one(nmeth): na\/nan\/inf nella chiamata di funzione esterna (arg 1)\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come correggere il seguente errore in R: errore in do_one(nmeth): na\/nan\/inf nella chiamata di funzione esterna (arg 1).\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/errore-in-do_onenmeth-na-nan-inf-nella-chiamata-di-funzione-esterna\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-24T18:20:52+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\/errore-in-do_onenmeth-na-nan-inf-nella-chiamata-di-funzione-esterna\/\",\"url\":\"https:\/\/statorials.org\/it\/errore-in-do_onenmeth-na-nan-inf-nella-chiamata-di-funzione-esterna\/\",\"name\":\"Come risolvere: errore in do_one(nmeth): na\/nan\/inf nella chiamata di funzione esterna (arg 1)\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-24T18:20:52+00:00\",\"dateModified\":\"2023-07-24T18:20:52+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come correggere il seguente errore in R: errore in do_one(nmeth): na\/nan\/inf nella chiamata di funzione esterna (arg 1).\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/errore-in-do_onenmeth-na-nan-inf-nella-chiamata-di-funzione-esterna\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/errore-in-do_onenmeth-na-nan-inf-nella-chiamata-di-funzione-esterna\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/errore-in-do_onenmeth-na-nan-inf-nella-chiamata-di-funzione-esterna\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Come risolvere: errore in do_one(nmeth): na\/nan\/inf nella chiamata di funzione esterna (arg 1)\"}]},{\"@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: errore in do_one(nmeth): na\/nan\/inf nella chiamata di funzione esterna (arg 1)","description":"Questo tutorial spiega come correggere il seguente errore in R: errore in do_one(nmeth): na\/nan\/inf nella chiamata di funzione esterna (arg 1).","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\/errore-in-do_onenmeth-na-nan-inf-nella-chiamata-di-funzione-esterna\/","og_locale":"it_IT","og_type":"article","og_title":"Come risolvere: errore in do_one(nmeth): na\/nan\/inf nella chiamata di funzione esterna (arg 1)","og_description":"Questo tutorial spiega come correggere il seguente errore in R: errore in do_one(nmeth): na\/nan\/inf nella chiamata di funzione esterna (arg 1).","og_url":"https:\/\/statorials.org\/it\/errore-in-do_onenmeth-na-nan-inf-nella-chiamata-di-funzione-esterna\/","og_site_name":"Statorials","article_published_time":"2023-07-24T18:20:52+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\/errore-in-do_onenmeth-na-nan-inf-nella-chiamata-di-funzione-esterna\/","url":"https:\/\/statorials.org\/it\/errore-in-do_onenmeth-na-nan-inf-nella-chiamata-di-funzione-esterna\/","name":"Come risolvere: errore in do_one(nmeth): na\/nan\/inf nella chiamata di funzione esterna (arg 1)","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-24T18:20:52+00:00","dateModified":"2023-07-24T18:20:52+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come correggere il seguente errore in R: errore in do_one(nmeth): na\/nan\/inf nella chiamata di funzione esterna (arg 1).","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/errore-in-do_onenmeth-na-nan-inf-nella-chiamata-di-funzione-esterna\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/errore-in-do_onenmeth-na-nan-inf-nella-chiamata-di-funzione-esterna\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/errore-in-do_onenmeth-na-nan-inf-nella-chiamata-di-funzione-esterna\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Come risolvere: errore in do_one(nmeth): na\/nan\/inf nella chiamata di funzione esterna (arg 1)"}]},{"@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\/1848"}],"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=1848"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/1848\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=1848"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=1848"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=1848"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}