{"id":2219,"date":"2023-07-23T05:12:02","date_gmt":"2023-07-23T05:12:02","guid":{"rendered":"https:\/\/statorials.org\/it\/r-riepilogare-le-statistiche-per-gruppo\/"},"modified":"2023-07-23T05:12:02","modified_gmt":"2023-07-23T05:12:02","slug":"r-riepilogare-le-statistiche-per-gruppo","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/r-riepilogare-le-statistiche-per-gruppo\/","title":{"rendered":"Come calcolare le statistiche riassuntive per gruppo in r"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Esistono due modi fondamentali per calcolare le statistiche di riepilogo del gruppo in R:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Metodo 1: utilizzare tapply() da Base R<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>tapply(df$value_col, df$group_col, summary)\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\"><strong>Metodo 2: utilizzare group_by() dal pacchetto dplyr<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #008000;\">library<\/span> (dplyr)\n\ndf %&gt;%\n  <span style=\"color: #3366ff;\">group_by<\/span> (group_col) %&gt;% \n  <span style=\"color: #3366ff;\">summarize<\/span> (min = min(value_col),\n            q1 = quantile(value_col, <span style=\"color: #008000;\">0.25<\/span> ),\n            median = median(value_col),\n            mean = mean(value_col),\n            q3 = quantile(value_col, <span style=\"color: #008000;\">0.75<\/span> ),\n            max = max(value_col))<\/strong><\/span><\/pre>\n<p> <span style=\"color: #000000;\">Gli esempi seguenti mostrano come utilizzare ciascun metodo nella pratica.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Metodo 1: utilizzare tapply() da Base R<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come utilizzare la funzione <strong>tapply()<\/strong> in R per calcolare le statistiche di riepilogo per gruppo:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008080;\">#create data frame\n<\/span>df &lt;- data. <span style=\"color: #3366ff;\">frame<\/span> (team=c('A', 'A', 'A', 'A', 'B', 'B', 'B', 'B'),\n                 points=c(99, 68, 86, 88, 95, 74, 78, 93),\n                 assists=c(22, 28, 31, 35, 34, 45, 28, 31),\n                 rebounds=c(30, 28, 24, 24, 30, 36, 30, 29))\n\n<span style=\"color: #008080;\">#calculate summary statistics of 'points' grouped by 'team'\n<\/span>tapply(df$points, df$team, summary)\n\n$A\n   Min. 1st Qu. Median Mean 3rd Qu. Max. \n  68.00 81.50 87.00 85.25 90.75 99.00 \n\n$B\n   Min. 1st Qu. Median Mean 3rd Qu. Max. \n   74.0 77.0 85.5 85.0 93.5 95.0 \n<\/span><\/span><\/strong><\/pre>\n<h3> <span style=\"color: #000000;\"><strong>Metodo 2: utilizzare group_by() dal pacchetto dplyr<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come utilizzare le funzioni <strong>group_by()<\/strong> e <strong>summary()<\/strong> nel pacchetto <a href=\"https:\/\/dplyr.tidyverse.org\/\" target=\"_blank\" rel=\"noopener\">dplyr<\/a> per calcolare le statistiche di riepilogo per gruppo:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008000;\">library<\/span> (dplyr)<\/span>\n\n#create data frame\n<\/span>df &lt;- data. <span style=\"color: #3366ff;\">frame<\/span> (team=c('A', 'A', 'A', 'A', 'B', 'B', 'B', 'B'),\n                 points=c(99, 68, 86, 88, 95, 74, 78, 93),\n                 assists=c(22, 28, 31, 35, 34, 45, 28, 31),\n                 rebounds=c(30, 28, 24, 24, 30, 36, 30, 29))\n\n<span style=\"color: #008080;\">#calculate summary statistics of 'points' grouped by 'team'\n<\/span>df %&gt;%\n  <span style=\"color: #3366ff;\">group_by<\/span> (team) %&gt;% \n  <span style=\"color: #3366ff;\">summarize<\/span> (min = min(points),\n            q1 = quantile(points, <span style=\"color: #008000;\">0.25<\/span> ),\n            median = median(points),\n            mean = mean(points),\n            q3 = quantile(points, <span style=\"color: #008000;\">0.75<\/span> ),\n            max = max(points))\n\n# A tibble: 2 x 7\n  team min q1 median mean q3 max\n         \n1 A 68 81.5 87 85.2 90.8 99\n2 B 74 77 85.5 85 93.5 95\n<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Tieni presente che entrambi i metodi restituiscono esattamente gli stessi risultati.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Vale la pena notare che l&#8217;approccio dplyr sar\u00e0 probabilmente pi\u00f9 veloce per i frame di dati pi\u00f9 grandi, ma entrambi i metodi funzioneranno in modo simile su frame di dati pi\u00f9 piccoli.<\/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 eseguire altre funzioni di raggruppamento 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\/somma-per-gruppo-in-r\/\" target=\"_blank\" rel=\"noopener\">Come calcolare la somma per gruppo in R<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/r-media-per-gruppo\/\" target=\"_blank\" rel=\"noopener\">Come calcolare la media per gruppo in R<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/somma-per-gruppo-in-r\/\" target=\"_blank\" rel=\"noopener\">Come calcolare la somma per gruppo in R<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Esistono due modi fondamentali per calcolare le statistiche di riepilogo del gruppo in R: Metodo 1: utilizzare tapply() da Base R tapply(df$value_col, df$group_col, summary) Metodo 2: utilizzare group_by() dal pacchetto dplyr library (dplyr) df %&gt;% group_by (group_col) %&gt;% summarize (min = min(value_col), q1 = quantile(value_col, 0.25 ), median = median(value_col), mean = mean(value_col), q3 = [&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 calcolare le statistiche riassuntive per gruppo in R - Statorials<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come calcolare le statistiche di riepilogo del gruppo 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\/r-riepilogare-le-statistiche-per-gruppo\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Come calcolare le statistiche riassuntive per gruppo in R - Statorials\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come calcolare le statistiche di riepilogo del gruppo in R, con diversi esempi.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/r-riepilogare-le-statistiche-per-gruppo\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-23T05:12:02+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-riepilogare-le-statistiche-per-gruppo\/\",\"url\":\"https:\/\/statorials.org\/it\/r-riepilogare-le-statistiche-per-gruppo\/\",\"name\":\"Come calcolare le statistiche riassuntive per gruppo in R - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-23T05:12:02+00:00\",\"dateModified\":\"2023-07-23T05:12:02+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come calcolare le statistiche di riepilogo del gruppo in R, con diversi esempi.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/r-riepilogare-le-statistiche-per-gruppo\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/r-riepilogare-le-statistiche-per-gruppo\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/r-riepilogare-le-statistiche-per-gruppo\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Come calcolare le statistiche riassuntive per gruppo in r\"}]},{\"@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 calcolare le statistiche riassuntive per gruppo in R - Statorials","description":"Questo tutorial spiega come calcolare le statistiche di riepilogo del gruppo 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\/r-riepilogare-le-statistiche-per-gruppo\/","og_locale":"it_IT","og_type":"article","og_title":"Come calcolare le statistiche riassuntive per gruppo in R - Statorials","og_description":"Questo tutorial spiega come calcolare le statistiche di riepilogo del gruppo in R, con diversi esempi.","og_url":"https:\/\/statorials.org\/it\/r-riepilogare-le-statistiche-per-gruppo\/","og_site_name":"Statorials","article_published_time":"2023-07-23T05:12:02+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-riepilogare-le-statistiche-per-gruppo\/","url":"https:\/\/statorials.org\/it\/r-riepilogare-le-statistiche-per-gruppo\/","name":"Come calcolare le statistiche riassuntive per gruppo in R - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-23T05:12:02+00:00","dateModified":"2023-07-23T05:12:02+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come calcolare le statistiche di riepilogo del gruppo in R, con diversi esempi.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/r-riepilogare-le-statistiche-per-gruppo\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/r-riepilogare-le-statistiche-per-gruppo\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/r-riepilogare-le-statistiche-per-gruppo\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Come calcolare le statistiche riassuntive per gruppo in r"}]},{"@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\/2219"}],"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=2219"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/2219\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=2219"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=2219"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=2219"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}