{"id":2960,"date":"2023-07-19T21:55:08","date_gmt":"2023-07-19T21:55:08","guid":{"rendered":"https:\/\/statorials.org\/it\/ottieni-la-funzione\/"},"modified":"2023-07-19T21:55:08","modified_gmt":"2023-07-19T21:55:08","slug":"ottieni-la-funzione","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/ottieni-la-funzione\/","title":{"rendered":"Come utilizzare la funzione get() in r per recuperare oggetti denominati"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\"><span style=\"color: #000000;\">\u00c8 possibile utilizzare la funzione <strong>get()<\/strong> in R per recuperare oggetti denominati.<\/span><\/span><\/p>\n<p> <span style=\"color: #000000;\">Ecco le tre funzioni <strong>get()<\/strong> pi\u00f9 comuni in R:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>1.<\/strong> <strong>get()<\/strong> \u2013 Ottieni un oggetto<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong>get(\" <span style=\"color: #ff0000;\">my_object<\/span> \")<\/strong><\/span><\/pre>\n<p> <span style=\"color: #000000;\"><strong>2.<\/strong> <strong>get0()<\/strong> \u2013 Recupera un oggetto, utilizzando un messaggio di errore personalizzato se non trovato<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong>get0(\" <span style=\"color: #ff0000;\">my_object<\/span> \", ifnotfound=\" <span style=\"color: #ff0000;\">does not exist<\/span> \")<\/strong><\/span><\/pre>\n<p> <span style=\"color: #000000;\"><strong>3.<\/strong> <strong>mget()<\/strong> \u2013 Recupera pi\u00f9 oggetti<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong>mget(c(\" <span style=\"color: #ff0000;\">my_object1<\/span> \", \" <span style=\"color: #ff0000;\">my_object2<\/span> \", \" <span style=\"color: #ff0000;\">my_object3<\/span> \"))<\/strong><\/span><\/pre>\n<p> <span style=\"color: #000000;\">Gli esempi seguenti mostrano come utilizzare nella pratica ciascuna funzione.<\/span><\/p>\n<h3> <strong><span style=\"color: #000000;\">Esempio 1: utilizzare get() per recuperare un oggetto<\/span><\/strong><\/h3>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come utilizzare la funzione <strong>get()<\/strong> per recuperare un oggetto nome:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #008080;\">#define vector of values\n<\/span>data1 &lt;- c(4, 5, 5, 6, 13, 18, 19, 15, 12)\n\n<span style=\"color: #008080;\">#get vector of values\n<\/span>get(\" <span style=\"color: #ff0000;\">data1<\/span> \")\n\n[1] 4 5 5 6 13 18 19 15 12\n<\/strong><\/span><\/pre>\n<p> <span style=\"color: #000000;\">Se l&#8217;oggetto indicato non esiste, questa funzione restituisce un errore:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #008080;\">#define vector of values\n<\/span>data1 &lt;- c(4, 5, 5, 6, 13, 18, 19, 15, 12)\n\n<span style=\"color: #008080;\">#attempt to get vector of values\n<\/span>get(\" <span style=\"color: #ff0000;\">data0<\/span> \")\n\nError in get(\"data0\"): object 'data0' not found\n<\/strong><\/span><\/pre>\n<h3> <strong><span style=\"color: #000000;\">Esempio 2: utilizzare get0() per recuperare un oggetto, utilizzando un messaggio di errore personalizzato<\/span><\/strong><\/h3>\n<p> <span style=\"color: #000000;\">Possiamo anche utilizzare la funzione <strong>get0()<\/strong> per recuperare un oggetto denominato in R e utilizzare un messaggio di errore personalizzato se l&#8217;oggetto non viene trovato:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #008080;\">#define vector of values\n<\/span>data1 &lt;- c(4, 5, 5, 6, 13, 18, 19, 15, 12)\n\n<span style=\"color: #008080;\">#attempt to get vector of values\n<\/span>get0(\" <span style=\"color: #ff0000;\">data0<\/span> \", ifnotfound=\" <span style=\"color: #ff0000;\">does not exist<\/span> \")\n\n[1] \u201cdoes not exist\u201d\n<\/strong><\/span><\/pre>\n<p> <span style=\"color: #000000;\">Poich\u00e9 l&#8217;oggetto denominato &#8220;data0&#8221; non esiste, la funzione <strong>get0()<\/strong> restituisce il messaggio di errore personalizzato che abbiamo creato.<\/span><\/p>\n<h3> <strong><span style=\"color: #000000;\">Esempio 3: utilizzare mget() per recuperare pi\u00f9 oggetti<\/span><\/strong><\/h3>\n<p> <span style=\"color: #000000;\">Possiamo usare la funzione <strong>mget()<\/strong> per recuperare pi\u00f9 oggetti con nome in R:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #008080;\">#define three vectors\n<span style=\"color: #000000;\">data1 &lt;- c(4, 5, 5, 6, 13, 18, 19, 15, 12)\ndata2 &lt;- c(\"A\", \"B\", \"C\", \"D\")\ndata3 &lt;- c(10, 20, 25, 30, 35)\n\n<span style=\"color: #008080;\">#get all three vectors\n<\/span>mget(c(\" <span style=\"color: #ff0000;\">data1<\/span> \", \" <span style=\"color: #ff0000;\">data2<\/span> \", \" <span style=\"color: #ff0000;\">data3<\/span> \"))\n\n$data1\n[1] 4 5 5 6 13 18 19 15 12\n\n$data2\n[1] \u201cA\u201d \u201cB\u201d \u201cC\u201d \u201cD\u201d\n\n$data3\n[1] 10 20 25 30 35\n<\/span><\/span><\/strong><\/span><\/pre>\n<p> <span style=\"color: #000000;\">Nota che se provassimo semplicemente a utilizzare la funzione <strong>get()<\/strong> , verrebbe restituito solo il primo oggetto nominato:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #008080;\">#define three vectors\n<span style=\"color: #000000;\">data1 &lt;- c(4, 5, 5, 6, 13, 18, 19, 15, 12)\ndata2 &lt;- c(\"A\", \"B\", \"C\", \"D\")\ndata3 &lt;- c(10, 20, 25, 30, 35)<\/span>\n\n#attempt to get all three vectors\n<span style=\"color: #000000;\">mget(c(\" <span style=\"color: #ff0000;\">data1<\/span> \", \" <span style=\"color: #ff0000;\">data2<\/span> \", \" <span style=\"color: #ff0000;\">data3<\/span> \"))\n\n[1] 4 5 5 6 13 18 19 15 12\n<\/span><\/span><\/strong><\/span><\/pre>\n<h3> <span style=\"color: #000000;\"><strong>Risorse addizionali<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">I seguenti tutorial spiegano come utilizzare altre funzioni comuni in R:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/it\/funzione-c-in-r\/\" target=\"_blank\" rel=\"noopener\">Come utilizzare la funzione c() in R<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/funzione-sprintfr\/\" target=\"_blank\" rel=\"noopener\">Come utilizzare la funzione sprintf() in R<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/sostituisci-la-funzione-in-r\/\" target=\"_blank\" rel=\"noopener\">Come utilizzare la funzione replace() in R<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u00c8 possibile utilizzare la funzione get() in R per recuperare oggetti denominati. Ecco le tre funzioni get() pi\u00f9 comuni in R: 1. get() \u2013 Ottieni un oggetto get(&#8221; my_object &#8220;) 2. get0() \u2013 Recupera un oggetto, utilizzando un messaggio di errore personalizzato se non trovato get0(&#8221; my_object &#8220;, ifnotfound=&#8221; does not exist &#8220;) 3. mget() [&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 utilizzare la funzione get() in R per recuperare oggetti con nome \u2013 Statorials<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come utilizzare la funzione get() in R per recuperare oggetti con nome, con diversi 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\/ottieni-la-funzione\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Come utilizzare la funzione get() in R per recuperare oggetti con nome \u2013 Statorials\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come utilizzare la funzione get() in R per recuperare oggetti con nome, con diversi esempi.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/ottieni-la-funzione\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-19T21:55:08+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\/ottieni-la-funzione\/\",\"url\":\"https:\/\/statorials.org\/it\/ottieni-la-funzione\/\",\"name\":\"Come utilizzare la funzione get() in R per recuperare oggetti con nome \u2013 Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-19T21:55:08+00:00\",\"dateModified\":\"2023-07-19T21:55:08+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come utilizzare la funzione get() in R per recuperare oggetti con nome, con diversi esempi.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/ottieni-la-funzione\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/ottieni-la-funzione\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/ottieni-la-funzione\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Come utilizzare la funzione get() in r per recuperare oggetti denominati\"}]},{\"@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 utilizzare la funzione get() in R per recuperare oggetti con nome \u2013 Statorials","description":"Questo tutorial spiega come utilizzare la funzione get() in R per recuperare oggetti con nome, con diversi 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\/ottieni-la-funzione\/","og_locale":"it_IT","og_type":"article","og_title":"Come utilizzare la funzione get() in R per recuperare oggetti con nome \u2013 Statorials","og_description":"Questo tutorial spiega come utilizzare la funzione get() in R per recuperare oggetti con nome, con diversi esempi.","og_url":"https:\/\/statorials.org\/it\/ottieni-la-funzione\/","og_site_name":"Statorials","article_published_time":"2023-07-19T21:55:08+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\/ottieni-la-funzione\/","url":"https:\/\/statorials.org\/it\/ottieni-la-funzione\/","name":"Come utilizzare la funzione get() in R per recuperare oggetti con nome \u2013 Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-19T21:55:08+00:00","dateModified":"2023-07-19T21:55:08+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come utilizzare la funzione get() in R per recuperare oggetti con nome, con diversi esempi.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/ottieni-la-funzione\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/ottieni-la-funzione\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/ottieni-la-funzione\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Come utilizzare la funzione get() in r per recuperare oggetti denominati"}]},{"@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\/2960"}],"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=2960"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/2960\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=2960"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=2960"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=2960"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}