{"id":4507,"date":"2023-07-10T13:48:00","date_gmt":"2023-07-10T13:48:00","guid":{"rendered":"https:\/\/statorials.org\/it\/creare-serie-temporali-in-r\/"},"modified":"2023-07-10T13:48:00","modified_gmt":"2023-07-10T13:48:00","slug":"creare-serie-temporali-in-r","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/creare-serie-temporali-in-r\/","title":{"rendered":"Come creare una serie temporale in r (con esempi)"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Il modo pi\u00f9 semplice per creare un oggetto serie temporale in R \u00e8 utilizzare la funzione <strong>ts()<\/strong> .<\/span><\/p>\n<p> <span style=\"color: #000000;\">Questa funzione utilizza la seguente sintassi di base:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>ts(dati, inizio, fine, frequenza)<\/strong><\/span><\/p>\n<p> <span style=\"color: #000000;\">Oro:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\"><strong>dati<\/strong> : un vettore o una matrice di valori di serie temporali<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>inizio<\/strong> : ora della prima osservazione<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>end<\/strong> : l&#8217;ora dell&#8217;ultima osservazione<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>frequenza<\/strong> : numero di osservazioni per unit\u00e0 di tempo.<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">Gli esempi seguenti mostrano come utilizzare nella pratica questa funzione per creare diversi oggetti di serie temporali.<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Esempio 1: creare una serie temporale con dati mensili<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Supponiamo di avere il seguente vettore chiamato <strong>dati<\/strong> che contiene il numero di vendite effettuate da un negozio al dettaglio per 20 mesi consecutivi, a partire dal 1 ottobre 2023:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#create vector of 20 values\n<\/span>data &lt;- c(6, 7, 7, 7, 8, 5, 8, 9, 4, 9, 12, 14, 14, 15, 18, 24, 20, 15, 24, 26)\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Possiamo usare la funzione <strong>ts()<\/strong> e specificare <strong>Frequency=12<\/strong> per creare un oggetto di serie temporale da questo vettore:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#create time series object from vector\n<\/span>ts_data &lt;- ts(data, start=c(2023, 10), frequency=12)\n\n<span style=\"color: #008080;\">#view time series object\n<\/span>ts_data\n\n     Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec\n2023 6 7 7\n2024 7 8 5 8 9 4 9 12 14 14 15 18\n2025 24 20 15 24 26                            \n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Si noti che il vettore dei valori \u00e8 stato convertito in un oggetto di serie temporale in cui i valori sono ora associati a un mese da ottobre 2023 a maggio 2025.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Possiamo anche usare la funzione <strong>class()<\/strong> per confermare che <strong>ts_data<\/strong> \u00e8 effettivamente un oggetto di serie temporali:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#display class of ts_data object\n<\/span>class(ts_data)\n\n [1] \u201cts\u201d\n<\/strong><\/pre>\n<h2> <span style=\"color: #000000;\"><strong>Esempio 2: creare una serie temporale con dati annuali<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Supponiamo di avere il seguente vettore chiamato <strong>data<\/strong> , che contiene il numero di vendite effettuate da un negozio al dettaglio per 20 anni consecutivi, a partire dal 2000:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#create vector of 20 values\n<\/span>data &lt;- c(6, 7, 7, 7, 8, 5, 8, 9, 4, 9, 12, 14, 14, 15, 18, 24, 20, 15, 24, 26)\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Possiamo usare la funzione <strong>ts()<\/strong> e specificare <strong>Frequency=1<\/strong> per creare un oggetto di serie temporale da questo vettore:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#create time series object from vector\n<\/span>ts_data &lt;- ts(data, start=2023, frequency=1)\n\n<span style=\"color: #008080;\">#view time series object\n<\/span>Time Series:\nStart = 2000 \nEnd = 2019 \nFrequency = 1 \n [1] 6 7 7 7 8 5 8 9 4 9 12 14 14 15 18 24 20 15 24 26 \n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Da notare che il vettore dei valori \u00e8 stato convertito in un oggetto serie temporale in cui i valori sono ora associati ad un anno dal 2000 al 2019.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Possiamo anche usare la funzione <strong>class()<\/strong> per confermare che <strong>ts_data<\/strong> \u00e8 effettivamente un oggetto di serie temporali:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#display class of ts_data object\n<\/span>class(ts_data)\n\n [1] \u201cts\u201d<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Se lo desideriamo, possiamo anche utilizzare la funzione <strong>plot()<\/strong> per visualizzare le vendite per anno:<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#create line plot of time series data\n<\/span>plot(ts_data)<\/strong> <\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-35210 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/ts1.png\" alt=\"\" width=\"471\" height=\"433\" srcset=\"\" sizes=\"\"><\/p>\n<p> <span style=\"color: #000000;\">Tieni presente che l&#8217;asse X mostra l&#8217;anno e l&#8217;asse Y mostra i valori delle vendite.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Possiamo anche personalizzare la trama per renderla pi\u00f9 facile da leggere:<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#create line plot with custom x-axis, y-axis, title, line color and line width\n<\/span>plot(ts_data, xlab=' <span style=\"color: #ff0000;\">Year<\/span> ', ylab=' <span style=\"color: #ff0000;\">Sales<\/span> ', main=' <span style=\"color: #ff0000;\">Sales by Year<\/span> ', col=' <span style=\"color: #ff0000;\">blue<\/span> ', lwd= <span style=\"color: #008000;\">3<\/span> )\n<\/strong><\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-35211 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/ts2.png\" alt=\"\" width=\"489\" height=\"459\" srcset=\"\" sizes=\"\"><\/p>\n<p> <span style=\"color: #000000;\">Sentiti libero di modificare gli argomenti della funzione <strong>plot()<\/strong> per creare l&#8217;esatto grafico della serie temporale che desideri.<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Risorse addizionali<\/strong><\/span><span style=\"color: #000000;\"><br \/><\/span><\/h2>\n<p> <span style=\"color: #000000;\">I seguenti tutorial spiegano come eseguire altre attivit\u00e0 comuni in R:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><a href=\"https:\/\/statorials.org\/it\/tracciare-le-serie-temporali-in-r\/\" target=\"_blank\" rel=\"noopener\">Come tracciare una serie temporale in R<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/r-convertire-il-frame-di-dati-in-serie-temporali\/\" target=\"_blank\" rel=\"noopener\">Come convertire un frame di dati in una serie temporale in R<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/converti-la-stringa-in-datetime-in-r\/\" target=\"_blank\" rel=\"noopener\">Come convertire una stringa in Datetime in R<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Il modo pi\u00f9 semplice per creare un oggetto serie temporale in R \u00e8 utilizzare la funzione ts() . Questa funzione utilizza la seguente sintassi di base: ts(dati, inizio, fine, frequenza) Oro: dati : un vettore o una matrice di valori di serie temporali inizio : ora della prima osservazione end : l&#8217;ora dell&#8217;ultima osservazione frequenza [&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 creare una serie temporale in R (con esempi) - Statorials<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come creare una serie temporale 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\/creare-serie-temporali-in-r\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Come creare una serie temporale in R (con esempi) - Statorials\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come creare una serie temporale in R, con diversi esempi.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/creare-serie-temporali-in-r\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-10T13:48:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/ts1.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=\"3 minuti\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/it\/creare-serie-temporali-in-r\/\",\"url\":\"https:\/\/statorials.org\/it\/creare-serie-temporali-in-r\/\",\"name\":\"Come creare una serie temporale in R (con esempi) - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-10T13:48:00+00:00\",\"dateModified\":\"2023-07-10T13:48:00+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come creare una serie temporale in R, con diversi esempi.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/creare-serie-temporali-in-r\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/creare-serie-temporali-in-r\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/creare-serie-temporali-in-r\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Come creare una serie temporale 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 creare una serie temporale in R (con esempi) - Statorials","description":"Questo tutorial spiega come creare una serie temporale 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\/creare-serie-temporali-in-r\/","og_locale":"it_IT","og_type":"article","og_title":"Come creare una serie temporale in R (con esempi) - Statorials","og_description":"Questo tutorial spiega come creare una serie temporale in R, con diversi esempi.","og_url":"https:\/\/statorials.org\/it\/creare-serie-temporali-in-r\/","og_site_name":"Statorials","article_published_time":"2023-07-10T13:48:00+00:00","og_image":[{"url":"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/ts1.png"}],"author":"Benjamin anderson","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Benjamin anderson","Est. reading time":"3 minuti"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/it\/creare-serie-temporali-in-r\/","url":"https:\/\/statorials.org\/it\/creare-serie-temporali-in-r\/","name":"Come creare una serie temporale in R (con esempi) - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-10T13:48:00+00:00","dateModified":"2023-07-10T13:48:00+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come creare una serie temporale in R, con diversi esempi.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/creare-serie-temporali-in-r\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/creare-serie-temporali-in-r\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/creare-serie-temporali-in-r\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Come creare una serie temporale 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\/4507"}],"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=4507"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/4507\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=4507"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=4507"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=4507"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}