{"id":2040,"date":"2023-07-23T23:41:54","date_gmt":"2023-07-23T23:41:54","guid":{"rendered":"https:\/\/statorials.org\/it\/r-loggetto-di-tipo-chiusura-non-e-regolabile\/"},"modified":"2023-07-23T23:41:54","modified_gmt":"2023-07-23T23:41:54","slug":"r-loggetto-di-tipo-chiusura-non-e-regolabile","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/r-loggetto-di-tipo-chiusura-non-e-regolabile\/","title":{"rendered":"Come gestire in r: l&#39;oggetto di tipo &quot;chiusura&quot; non \u00e8 sottodefinibile"},"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>object of type 'closure' is not subsettable\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Questo errore si verifica quando si tenta di creare un sottoinsieme di una funzione.<\/span><\/p>\n<p> <span style=\"color: #000000;\">In R \u00e8 possibile sottoinsieme liste, vettori, matrici e frame di dati, ma una funzione ha tipo &#8220;chiusura&#8221; che non pu\u00f2 essere sottoinsieme.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Questo tutorial spiega esattamente come risolvere questo errore.<\/span><\/p>\n<h3> <strong>Come riprodurre l&#8217;errore<\/strong><\/h3>\n<p> <span style=\"color: #000000;\">Supponiamo di creare la seguente funzione in R che prende ogni valore di un vettore e lo moltiplica per 5:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #008080;\">#define function\n<span style=\"color: #000000;\">cool_function &lt;- <span style=\"color: #008000;\">function<\/span> (x) {\n  x &lt;- x*5\n  <span style=\"color: #008000;\">return<\/span> (x)\n}\n<\/span><\/span><\/strong><\/span><\/pre>\n<p> <span style=\"color: #000000;\">Ecco come potremmo utilizzare questa funzione nella pratica:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008080;\">#define data\n<\/span>data &lt;- c(2, 3, 3, 4, 5, 5, 6, 9)\n\n<span style=\"color: #008080;\">#apply function to data\n<\/span>cool_function(data)\n\n[1] 10 15 15 20 25 25 30 45\n<\/span><\/span><\/strong><\/span><\/pre>\n<p> <span style=\"color: #000000;\">Nota che ogni valore del vettore originale \u00e8 stato moltiplicato per 5.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Supponiamo ora di provare a sottoimpostare la funzione:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #008080;\">#attempt to get first element of function\n<span style=\"color: #000000;\">cool_function[1]\n\nError in cool_function[1]: object of type 'closure' is not subsettable\n<\/span><\/span><\/strong><\/span><\/pre>\n<p> <span style=\"color: #000000;\">Riceviamo un errore perch\u00e9 non \u00e8 possibile sottoimpostare un oggetto di tipo &#8220;chiusura&#8221; in R.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Possiamo utilizzare la seguente sintassi per verificare che la funzione sia effettivamente di tipo &#8216;chiusura&#8217;:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #008080;\">#print object type of function\n<span style=\"color: #000000;\">typeof(cool_function)\n\n[1] \u201cclosure\u201d\n<\/span><\/span><\/strong><\/span><\/pre>\n<h3> <span style=\"color: #000000;\"><strong>Altri esempi di oggetti \u201cChiusura\u201d.<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Ogni funzione in R \u00e8 di tipo \u201cchiusura\u201d. Ad esempio, riceveremmo questo errore se provassimo a creare un sottoinsieme di qualsiasi funzione nella base R:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #008080;\">#attempt to subset mean function<\/span>\nmean[1]\n\nError in mean[1]: object of type 'closure' is not subsettable\n\n<span style=\"color: #008080;\">#attempt to subset standard deviation function\n<\/span>sd[1]\n\nError in sd[1]: object of type 'closure' is not subsettable\n\n<span style=\"color: #008080;\">#attempt to subset table function\n<\/span>tabld[1]\n\nError in table[1]: object of type 'closure' is not subsettable\n<\/strong><\/span><\/pre>\n<h3> <span style=\"color: #000000;\"><strong>Come risolvere l&#8217;errore<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Il modo per risolvere questo errore \u00e8 semplicemente evitare di sottodefinire una funzione.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Ad esempio, se vogliamo applicare la nostra precedente <strong>funzione cool_function<\/strong> solo al primo elemento di un vettore, possiamo utilizzare la seguente sintassi:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><b><span style=\"color: #008080;\">#apply function to just first element in vector<\/span>\ncool_function(data[1])\n\n[1] 10\n<\/b><\/span><\/pre>\n<p> <span style=\"color: #000000;\">Non riceviamo un errore perch\u00e9 sottoinseriamo il vettore invece della funzione.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Oppure potremmo applicare <strong>cool_function<\/strong> all&#8217;intero vettore:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><b><span style=\"color: #008080;\">#apply function to every element in vector<\/span>\ncool_function(data)\n\n[1] 10 15 15 20 25 25 30 45<\/b><\/span><\/pre>\n<p> <span style=\"color: #000000;\">Non riceviamo un errore perch\u00e9 non abbiamo tentato di creare un sottoinsieme della funzione in alcun modo.<\/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 risolvere altri errori comuni in R:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/it\/la-condizione-r-ha-lunghezza-1-verra-utilizzato-solo-il-primo-elemento\/\" target=\"_blank\" rel=\"noopener\">Come risolvere il problema: la condizione ha lunghezza &gt; 1 e verr\u00e0 utilizzato solo il primo elemento<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/r-error-dim-deve-avere-una-lunghezza-positiva\/\" target=\"_blank\" rel=\"noopener\">Come risolvere in R: dim(X) deve avere una lunghezza positiva<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/r-valore-mancante-o-vero-falso-necessario\/\" target=\"_blank\" rel=\"noopener\">Come risolvere in R: valore mancante dove \u00e8 necessario vero\/falso<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/nas-introdotto-con-la-coercizione-in-r\/\" target=\"_blank\" rel=\"noopener\">Come risolvere: NA introdotte dalla coercizione<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Un errore che potresti riscontrare in R \u00e8: object of type &#8216;closure&#8217; is not subsettable Questo errore si verifica quando si tenta di creare un sottoinsieme di una funzione. In R \u00e8 possibile sottoinsieme liste, vettori, matrici e frame di dati, ma una funzione ha tipo &#8220;chiusura&#8221; che non pu\u00f2 essere sottoinsieme. Questo tutorial spiega [&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 gestire in R: oggetto di tipo \u201cchiusura\u201d non \u00e8 sottoimpostabile - Statorials<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come gestire il seguente errore in R: l&#039;oggetto di tipo &quot;chiusura&quot; non \u00e8 sottoimpostabile.\" \/>\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-loggetto-di-tipo-chiusura-non-e-regolabile\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Come gestire in R: oggetto di tipo \u201cchiusura\u201d non \u00e8 sottoimpostabile - Statorials\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come gestire il seguente errore in R: l&#039;oggetto di tipo &quot;chiusura&quot; non \u00e8 sottoimpostabile.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/r-loggetto-di-tipo-chiusura-non-e-regolabile\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-23T23:41:54+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\/r-loggetto-di-tipo-chiusura-non-e-regolabile\/\",\"url\":\"https:\/\/statorials.org\/it\/r-loggetto-di-tipo-chiusura-non-e-regolabile\/\",\"name\":\"Come gestire in R: oggetto di tipo \u201cchiusura\u201d non \u00e8 sottoimpostabile - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-23T23:41:54+00:00\",\"dateModified\":\"2023-07-23T23:41:54+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come gestire il seguente errore in R: l&#39;oggetto di tipo &quot;chiusura&quot; non \u00e8 sottoimpostabile.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/r-loggetto-di-tipo-chiusura-non-e-regolabile\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/r-loggetto-di-tipo-chiusura-non-e-regolabile\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/r-loggetto-di-tipo-chiusura-non-e-regolabile\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Come gestire in r: l&#39;oggetto di tipo &quot;chiusura&quot; non \u00e8 sottodefinibile\"}]},{\"@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 gestire in R: oggetto di tipo \u201cchiusura\u201d non \u00e8 sottoimpostabile - Statorials","description":"Questo tutorial spiega come gestire il seguente errore in R: l&#39;oggetto di tipo &quot;chiusura&quot; non \u00e8 sottoimpostabile.","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-loggetto-di-tipo-chiusura-non-e-regolabile\/","og_locale":"it_IT","og_type":"article","og_title":"Come gestire in R: oggetto di tipo \u201cchiusura\u201d non \u00e8 sottoimpostabile - Statorials","og_description":"Questo tutorial spiega come gestire il seguente errore in R: l&#39;oggetto di tipo &quot;chiusura&quot; non \u00e8 sottoimpostabile.","og_url":"https:\/\/statorials.org\/it\/r-loggetto-di-tipo-chiusura-non-e-regolabile\/","og_site_name":"Statorials","article_published_time":"2023-07-23T23:41:54+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\/r-loggetto-di-tipo-chiusura-non-e-regolabile\/","url":"https:\/\/statorials.org\/it\/r-loggetto-di-tipo-chiusura-non-e-regolabile\/","name":"Come gestire in R: oggetto di tipo \u201cchiusura\u201d non \u00e8 sottoimpostabile - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-23T23:41:54+00:00","dateModified":"2023-07-23T23:41:54+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come gestire il seguente errore in R: l&#39;oggetto di tipo &quot;chiusura&quot; non \u00e8 sottoimpostabile.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/r-loggetto-di-tipo-chiusura-non-e-regolabile\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/r-loggetto-di-tipo-chiusura-non-e-regolabile\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/r-loggetto-di-tipo-chiusura-non-e-regolabile\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Come gestire in r: l&#39;oggetto di tipo &quot;chiusura&quot; non \u00e8 sottodefinibile"}]},{"@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\/2040"}],"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=2040"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/2040\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=2040"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=2040"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=2040"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}