{"id":1101,"date":"2023-07-27T16:12:17","date_gmt":"2023-07-27T16:12:17","guid":{"rendered":"https:\/\/statorials.org\/it\/somma-cumulativa-in-r\/"},"modified":"2023-07-27T16:12:17","modified_gmt":"2023-07-27T16:12:17","slug":"somma-cumulativa-in-r","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/somma-cumulativa-in-r\/","title":{"rendered":"Come calcolare le somme cumulative in r (con esempi)"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\"><span style=\"color: #000000;\">\u00c8 possibile utilizzare la funzione R base <strong>cumsum()<\/strong> per calcolare facilmente la somma cumulativa di un vettore di valori numerici.<\/span><\/span><\/p>\n<p> <span style=\"color: #000000;\">Questo tutorial spiega come utilizzare questa funzione per calcolare la somma cumulativa di un vettore e come visualizzare una somma cumulativa.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Come calcolare una somma cumulativa in R<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come calcolare la somma cumulativa delle vendite per una determinata societ\u00e0 in 15 trimestri di vendita:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#create dataset<\/span>\ndata &lt;- data.frame(quarter=1:15,\n                   sales=c(1, 2, 2, 5, 4, 7, 5, 7, 6, 8, 5, 9, 11, 12, 4))\n\n<span style=\"color: #008080;\">#create new column in dataset that contains cumulative sales<\/span>\ndata$cum_sales &lt;- <span style=\"color: #3366ff;\">cumsum<\/span> (data$sales)\n\n<span style=\"color: #008080;\">#view dataset<\/span>\ndata\n\n   quarter sales cum_sales\n1 1 1 1\n2 2 2 3\n3 3 2 5\n4 4 5 10\n5 5 4 14\n6 6 7 21\n7 7 5 26\n8 8 7 33\n9 9 6 39\n10 10 8 47\n11 11 5 52\n12 12 9 61\n13 13 11 72\n14 14 12 84\n15 15 4 88\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">I valori visualizzati nella colonna <strong>cum_sales<\/strong> rappresentano le vendite totali fino a quel trimestre compreso. Ad esempio, le vendite cumulative per il quinto trimestre vengono calcolate come segue: 1+2+2+5+4 = <strong>14<\/strong> .<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Come visualizzare una somma corrente in R<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Una volta calcolate le vendite cumulative, possiamo creare un semplice grafico a linee basato su R per visualizzare le vendite cumulative per trimestre:<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>plot(data$cum_sales, type=' <span style=\"color: #008000;\">l<\/span> ', xlab=' <span style=\"color: #008000;\">Quarter<\/span> ', ylab=' <span style=\"color: #008000;\">Cumulative Sales<\/span> ')\n<\/strong><\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-11220 \" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/cumsum1.png\" alt=\"Grafico a linee per la somma cumulativa in R\" width=\"460\" height=\"427\" srcset=\"\" sizes=\"\"><\/p>\n<p> <span style=\"color: #000000;\">In alternativa, possiamo utilizzare la libreria di visualizzazione R <a href=\"https:\/\/ggplot2.tidyverse.org\/\" target=\"_blank\" rel=\"noopener noreferrer\">ggplot2<\/a> per creare lo stesso grafico a linee:<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #993300;\">library<\/span> (ggplot2)\n\nggplot(data, aes(x=quarter, y=cum_sales)) +\n  geom_line() +\n  labs(x=' <span style=\"color: #008000;\">Quarter<\/span> ', y=' <span style=\"color: #008000;\">Cumulative Sales<\/span> ')<\/strong> <\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-11221 \" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/cumsum2.png\" alt=\"Trama della somma cumulativa in ggplot2\" width=\"464\" height=\"457\" srcset=\"\" sizes=\"\"><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Risorse addizionali<\/strong><\/span><\/h3>\n<p> <a href=\"https:\/\/statorials.org\/it\/media-tra-le-colonne-in-r\/\" target=\"_blank\" rel=\"noopener noreferrer\">Come calcolare la media sulle colonne in R<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/aggiungi-colonne-specifiche-in-r\/\" target=\"_blank\" rel=\"noopener noreferrer\">Come sommare colonne specifiche in R<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/conta-se-r\/\" target=\"_blank\" rel=\"noopener noreferrer\">Come eseguire una funzione CONTA.SE in R<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u00c8 possibile utilizzare la funzione R base cumsum() per calcolare facilmente la somma cumulativa di un vettore di valori numerici. Questo tutorial spiega come utilizzare questa funzione per calcolare la somma cumulativa di un vettore e come visualizzare una somma cumulativa. Come calcolare una somma cumulativa in R Il codice seguente mostra come calcolare la [&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 somme cumulative in R (con esempi) \u2013 Statorials<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come calcolare le somme cumulative 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\/somma-cumulativa-in-r\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Come calcolare le somme cumulative in R (con esempi) \u2013 Statorials\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come calcolare le somme cumulative in R, con diversi esempi.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/somma-cumulativa-in-r\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-27T16:12:17+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/cumsum1.png\" \/>\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=\"1 minuto\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/it\/somma-cumulativa-in-r\/\",\"url\":\"https:\/\/statorials.org\/it\/somma-cumulativa-in-r\/\",\"name\":\"Come calcolare le somme cumulative in R (con esempi) \u2013 Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-27T16:12:17+00:00\",\"dateModified\":\"2023-07-27T16:12:17+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come calcolare le somme cumulative in R, con diversi esempi.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/somma-cumulativa-in-r\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/somma-cumulativa-in-r\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/somma-cumulativa-in-r\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Come calcolare le somme cumulative 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 calcolare le somme cumulative in R (con esempi) \u2013 Statorials","description":"Questo tutorial spiega come calcolare le somme cumulative 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\/somma-cumulativa-in-r\/","og_locale":"it_IT","og_type":"article","og_title":"Come calcolare le somme cumulative in R (con esempi) \u2013 Statorials","og_description":"Questo tutorial spiega come calcolare le somme cumulative in R, con diversi esempi.","og_url":"https:\/\/statorials.org\/it\/somma-cumulativa-in-r\/","og_site_name":"Statorials","article_published_time":"2023-07-27T16:12:17+00:00","og_image":[{"url":"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/cumsum1.png"}],"author":"Benjamin anderson","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Benjamin anderson","Est. reading time":"1 minuto"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/it\/somma-cumulativa-in-r\/","url":"https:\/\/statorials.org\/it\/somma-cumulativa-in-r\/","name":"Come calcolare le somme cumulative in R (con esempi) \u2013 Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-27T16:12:17+00:00","dateModified":"2023-07-27T16:12:17+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come calcolare le somme cumulative in R, con diversi esempi.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/somma-cumulativa-in-r\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/somma-cumulativa-in-r\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/somma-cumulativa-in-r\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Come calcolare le somme cumulative 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\/1101"}],"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=1101"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/1101\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=1101"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=1101"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=1101"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}