{"id":4273,"date":"2023-07-12T09:24:57","date_gmt":"2023-07-12T09:24:57","guid":{"rendered":"https:\/\/statorials.org\/it\/ordinare-la-tabella-in-r\/"},"modified":"2023-07-12T09:24:57","modified_gmt":"2023-07-12T09:24:57","slug":"ordinare-la-tabella-in-r","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/ordinare-la-tabella-in-r\/","title":{"rendered":"Come ordinare una tabella in r (con esempi)"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\"><span style=\"color: #000000;\">Esistono due metodi che \u00e8 possibile utilizzare per ordinare una tabella in R:<\/span><\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong><span style=\"color: #000000;\">Metodo 1: utilizzare Base R<\/span><\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #008080;\"><strong>#sort table in ascending order<\/strong><\/span>\n<span style=\"color: #000000;\"><strong>my_table_sorted &lt;- my_table[order(my_table)]\n\n<span style=\"color: #008080;\">#sort table in descending order<\/span>\nmy_table_sorted &lt;- my_table[order(my_table, decreasing= <span style=\"color: #008000;\">TRUE<\/span> )]\n<\/strong><\/span><\/pre>\n<p> <span style=\"color: #000000;\"><strong>Metodo 2: usa dplyr<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\">library<\/span> (dplyr)\n\n<span style=\"color: #008080;\">#sort table in ascending order<\/span><\/strong>\n<strong>my_table_sorted&lt;- my_table %&gt;% as. <span style=\"color: #3366ff;\">data<\/span> . <span style=\"color: #3366ff;\">frame<\/span> () %&gt;% arrange(Freq)\n\n<span style=\"color: #008080;\">#sort table in descending order<\/span>\nmy_table_sorted&lt;- my_table %&gt;% as. <span style=\"color: #3366ff;\">data<\/span> . <span style=\"color: #3366ff;\">frame<\/span> () %&gt;% arrange(desc(Freq))\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\"><span style=\"color: #000000;\">I seguenti esempi mostrano come utilizzare ciascun metodo nella pratica con la seguente tabella in R:<\/span><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#createvector\n<span style=\"color: #000000;\">data &lt;- c(3, 8, 8, 8, 7, 7, 5, 5, 5, 5, 9, 12, 15, 15)\n<\/span>\n#create table\n<span style=\"color: #000000;\">my_table &lt;- table(data)\n<\/span>\n#view table\n<span style=\"color: #000000;\">my_table\n\ndata\n 3 5 7 8 9 12 15 \n 1 4 2 3 1 1 2\n<\/span><\/span><\/strong><\/pre>\n<h2> <span style=\"color: #000000;\"><strong>Esempio 1: ordinare la tabella utilizzando Base R<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Possiamo utilizzare il seguente codice per ordinare i valori dell&#8217;array in ordine crescente utilizzando la funzione R base <strong>order()<\/strong> :<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#sort table in ascending order\n<span style=\"color: #000000;\">my_table_sorted &lt;- my_table[order(my_table)]\n\n<span style=\"color: #008080;\">#view sorted table\n<\/span>my_table_sorted\n\ndata\n 3 9 12 7 15 8 5 \n 1 1 1 2 2 3 4<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">E possiamo usare l&#8217;argomento <strong>descending=True<\/strong> nella funzione <strong>order()<\/strong> per ordinare i valori dell&#8217;array in ordine decrescente:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#sort table in descending order\n<span style=\"color: #000000;\">my_table_sorted &lt;- my_table[order(my_table, decreasing= <span style=\"color: #008000;\">TRUE<\/span> )]\n\n<span style=\"color: #008080;\">#view sorted table<\/span>\nmy_table_sorted\n<\/span>\n<\/span>data\n 5 8 7 15 3 9 12 \n 4 3 2 2 1 1 1<\/strong><\/pre>\n<h2> <span style=\"color: #000000;\"><strong>Esempio 2: ordinare la tabella utilizzando dplyr<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Possiamo usare il seguente codice per ordinare i valori dell&#8217;array in ordine crescente utilizzando la funzione <strong>organizzare()<\/strong> dal pacchetto dplyr:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008000;\">library<\/span> (dplyr)<\/span>\n\n#sort table in ascending order\n<span style=\"color: #000000;\">my_table_sorted &lt;- my_table %&gt;% as. <span style=\"color: #3366ff;\">data<\/span> . <span style=\"color: #3366ff;\">frame<\/span> () %&gt;% arrange(Freq)\n\n<span style=\"color: #008080;\">#view sorted table<\/span>\nmy_table_sorted\n\n  data Freq\n1 3 1\n2 9 1\n3 12 1\n4 7 2\n5 15 2\n6 8 3\n7 5 4<\/span>\n<\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">E possiamo usare la funzione <strong>desc()<\/strong> per ordinare i valori dell&#8217;array in ordine decrescente:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008000;\">library<\/span> (dplyr)<\/span>\n\n#sort table in descending order\n<span style=\"color: #000000;\">my_table_sorted &lt;- my_table %&gt;% as. <span style=\"color: #3366ff;\">data<\/span> . <span style=\"color: #3366ff;\">frame<\/span> () %&gt;% arrange(desc(Freq))\n\n<span style=\"color: #008080;\">#view sorted table\n<\/span>my_table_sorted\n\n  data Freq\n1 5 4\n2 8 3\n3 7 2\n4 15 2\n5 3 1\n6 9 1\n7 12 1\n<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\"><strong>Nota<\/strong> : puoi trovare la documentazione completa per la funzione dplyr <strong>organizzare()<\/strong> <a href=\"https:\/\/dplyr.tidyverse.org\/reference\/arrange.html\" target=\"_blank\" rel=\"noopener\">qui<\/a> .<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Risorse addizionali<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">I seguenti tutorial spiegano come eseguire altre attivit\u00e0 comuni in R:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/it\/r-tabella-delle-frequenze-per-gruppo\/\" target=\"_blank\" rel=\"noopener\">Come creare una tabella di frequenza per gruppo in R<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/tavolo-a-due-vie-a-r\/\" target=\"_blank\" rel=\"noopener\">Come creare una tabella a due vie in R<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/disegnare-la-tabella-a-r\/\" target=\"_blank\" rel=\"noopener\">Come tracciare una tabella in R<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Esistono due metodi che \u00e8 possibile utilizzare per ordinare una tabella in R: Metodo 1: utilizzare Base R #sort table in ascending order my_table_sorted &lt;- my_table[order(my_table)] #sort table in descending order my_table_sorted &lt;- my_table[order(my_table, decreasing= TRUE )] Metodo 2: usa dplyr library (dplyr) #sort table in ascending order my_table_sorted&lt;- my_table %&gt;% as. data . frame [&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 ordinare una tabella in R (con esempi) \u2013 Statorials<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come ordinare una tabella in R, 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\/ordinare-la-tabella-in-r\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Come ordinare una tabella in R (con esempi) \u2013 Statorials\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come ordinare una tabella in R, con diversi esempi.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/ordinare-la-tabella-in-r\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-12T09:24:57+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\/ordinare-la-tabella-in-r\/\",\"url\":\"https:\/\/statorials.org\/it\/ordinare-la-tabella-in-r\/\",\"name\":\"Come ordinare una tabella in R (con esempi) \u2013 Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-12T09:24:57+00:00\",\"dateModified\":\"2023-07-12T09:24:57+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come ordinare una tabella in R, con diversi esempi.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/ordinare-la-tabella-in-r\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/ordinare-la-tabella-in-r\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/ordinare-la-tabella-in-r\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Come ordinare una tabella in r (con esempi)\"}]},{\"@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 ordinare una tabella in R (con esempi) \u2013 Statorials","description":"Questo tutorial spiega come ordinare una tabella in R, 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\/ordinare-la-tabella-in-r\/","og_locale":"it_IT","og_type":"article","og_title":"Come ordinare una tabella in R (con esempi) \u2013 Statorials","og_description":"Questo tutorial spiega come ordinare una tabella in R, con diversi esempi.","og_url":"https:\/\/statorials.org\/it\/ordinare-la-tabella-in-r\/","og_site_name":"Statorials","article_published_time":"2023-07-12T09:24:57+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\/ordinare-la-tabella-in-r\/","url":"https:\/\/statorials.org\/it\/ordinare-la-tabella-in-r\/","name":"Come ordinare una tabella in R (con esempi) \u2013 Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-12T09:24:57+00:00","dateModified":"2023-07-12T09:24:57+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come ordinare una tabella in R, con diversi esempi.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/ordinare-la-tabella-in-r\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/ordinare-la-tabella-in-r\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/ordinare-la-tabella-in-r\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Come ordinare una tabella in r (con esempi)"}]},{"@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\/4273"}],"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=4273"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/4273\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=4273"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=4273"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=4273"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}