{"id":4505,"date":"2023-07-10T13:48:00","date_gmt":"2023-07-10T13:48:00","guid":{"rendered":"https:\/\/statorials.org\/pt\/criar-series-temporais-em-r\/"},"modified":"2023-07-10T13:48:00","modified_gmt":"2023-07-10T13:48:00","slug":"criar-series-temporais-em-r","status":"publish","type":"post","link":"https:\/\/statorials.org\/pt\/criar-series-temporais-em-r\/","title":{"rendered":"Como criar uma s\u00e9rie temporal em r (com exemplos)"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">A maneira mais f\u00e1cil de criar um objeto de s\u00e9rie temporal em R \u00e9 usar a fun\u00e7\u00e3o <strong>ts()<\/strong> .<\/span><\/p>\n<p> <span style=\"color: #000000;\">Esta fun\u00e7\u00e3o usa a seguinte sintaxe b\u00e1sica:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>ts(dados, in\u00edcio, fim, frequ\u00eancia)<\/strong><\/span><\/p>\n<p> <span style=\"color: #000000;\">Ouro:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\"><strong>dados<\/strong> : um vetor ou matriz de valores de s\u00e9ries temporais<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>in\u00edcio<\/strong> : hora da primeira observa\u00e7\u00e3o<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>end<\/strong> : A hora da \u00faltima observa\u00e7\u00e3o<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>frequ\u00eancia<\/strong> : O n\u00famero de observa\u00e7\u00f5es por unidade de tempo.<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">Os exemplos a seguir mostram como usar esta fun\u00e7\u00e3o para criar diferentes objetos de s\u00e9rie temporal na pr\u00e1tica.<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Exemplo 1: Crie uma s\u00e9rie temporal com dados mensais<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Suponha que temos o seguinte vetor denominado <strong>dados<\/strong> que cont\u00e9m o n\u00famero de vendas realizadas por uma loja de varejo durante 20 meses consecutivos, a partir de 1\u00ba de outubro de 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;\">Podemos usar a fun\u00e7\u00e3o <strong>ts()<\/strong> e especificar <strong>Frequency=12<\/strong> para criar um objeto de s\u00e9rie temporal a partir deste vetor:<\/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;\">Observe que o vetor de valores foi convertido em um objeto de s\u00e9rie temporal onde os valores agora est\u00e3o associados a um m\u00eas de outubro de 2023 a maio de 2025.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Tamb\u00e9m podemos usar a fun\u00e7\u00e3o <strong>class()<\/strong> para confirmar que <strong>ts_data<\/strong> \u00e9 de fato um objeto de s\u00e9rie temporal:<\/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>Exemplo 2: Crie uma s\u00e9rie temporal com dados anuais<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Suponha que temos o seguinte vetor denominado <strong>data<\/strong> , que cont\u00e9m o n\u00famero de vendas realizadas por uma loja de varejo durante 20 anos consecutivos, come\u00e7ando em 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;\">Podemos usar a fun\u00e7\u00e3o <strong>ts()<\/strong> e especificar <strong>Frequency=1<\/strong> para criar um objeto de s\u00e9rie temporal a partir deste vetor:<\/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;\">Observe que o vetor de valores foi convertido em um objeto de s\u00e9rie temporal onde os valores agora est\u00e3o associados a um ano de 2000 a 2019.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Tamb\u00e9m podemos usar a fun\u00e7\u00e3o <strong>class()<\/strong> para confirmar que <strong>ts_data<\/strong> \u00e9 de fato um objeto de s\u00e9rie temporal:<\/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 desejarmos, tamb\u00e9m podemos usar a fun\u00e7\u00e3o <strong>plot()<\/strong> para visualizar as vendas por ano:<\/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=\"auto, \"><\/p>\n<p> <span style=\"color: #000000;\">Observe que o eixo X exibe o ano e o eixo Y exibe os valores de vendas.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Tamb\u00e9m podemos personalizar o gr\u00e1fico para facilitar a leitura:<\/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=\"auto, \"><\/p>\n<p> <span style=\"color: #000000;\">Sinta-se \u00e0 vontade para modificar os argumentos da fun\u00e7\u00e3o <strong>plot()<\/strong> para criar o gr\u00e1fico de s\u00e9rie temporal exato que voc\u00ea deseja.<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Recursos adicionais<\/strong><\/span><span style=\"color: #000000;\"><br \/><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Os tutoriais a seguir explicam como realizar outras tarefas comuns em R:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><a href=\"https:\/\/statorials.org\/pt\/tracar-series-temporais-em-r\/\" target=\"_blank\" rel=\"noopener\">Como tra\u00e7ar uma s\u00e9rie temporal em R<\/a><br \/> <a href=\"https:\/\/statorials.org\/pt\/r-converter-quadro-de-dados-em-serie-temporal\/\" target=\"_blank\" rel=\"noopener\">Como converter um quadro de dados em uma s\u00e9rie temporal em R<\/a><br \/> <a href=\"https:\/\/statorials.org\/pt\/converter-string-para-data-e-hora-em-r\/\" target=\"_blank\" rel=\"noopener\">Como converter uma string para Datetime em R<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>A maneira mais f\u00e1cil de criar um objeto de s\u00e9rie temporal em R \u00e9 usar a fun\u00e7\u00e3o ts() . Esta fun\u00e7\u00e3o usa a seguinte sintaxe b\u00e1sica: ts(dados, in\u00edcio, fim, frequ\u00eancia) Ouro: dados : um vetor ou matriz de valores de s\u00e9ries temporais in\u00edcio : hora da primeira observa\u00e7\u00e3o end : A hora da \u00faltima observa\u00e7\u00e3o [&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":[],"class_list":["post-4505","post","type-post","status-publish","format-standard","hentry","category-guia"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Como criar uma s\u00e9rie temporal em R (com exemplos) - Statorials<\/title>\n<meta name=\"description\" content=\"Este tutorial explica como criar uma s\u00e9rie temporal em R, com v\u00e1rios exemplos.\" \/>\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\/pt\/criar-series-temporais-em-r\/\" \/>\n<meta property=\"og:locale\" content=\"pt_PT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Como criar uma s\u00e9rie temporal em R (com exemplos) - Statorials\" \/>\n<meta property=\"og:description\" content=\"Este tutorial explica como criar uma s\u00e9rie temporal em R, com v\u00e1rios exemplos.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/pt\/criar-series-temporais-em-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=\"Dr. benjamim anderson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Escrito por\" \/>\n\t<meta name=\"twitter:data1\" content=\"Dr. benjamim anderson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Tempo estimado de leitura\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutos\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/pt\/criar-series-temporais-em-r\/\",\"url\":\"https:\/\/statorials.org\/pt\/criar-series-temporais-em-r\/\",\"name\":\"Como criar uma s\u00e9rie temporal em R (com exemplos) - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/pt\/#website\"},\"datePublished\":\"2023-07-10T13:48:00+00:00\",\"dateModified\":\"2023-07-10T13:48:00+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666\"},\"description\":\"Este tutorial explica como criar uma s\u00e9rie temporal em R, com v\u00e1rios exemplos.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/pt\/criar-series-temporais-em-r\/#breadcrumb\"},\"inLanguage\":\"pt-PT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/pt\/criar-series-temporais-em-r\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/pt\/criar-series-temporais-em-r\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Lar\",\"item\":\"https:\/\/statorials.org\/pt\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Como criar uma s\u00e9rie temporal em r (com exemplos)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/statorials.org\/pt\/#website\",\"url\":\"https:\/\/statorials.org\/pt\/\",\"name\":\"Statorials\",\"description\":\"O seu guia para a literacia estat\u00edstica!\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/statorials.org\/pt\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"pt-PT\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666\",\"name\":\"Dr. benjamim anderson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"pt-PT\",\"@id\":\"https:\/\/statorials.org\/pt\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/statorials.org\/pt\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"contentUrl\":\"https:\/\/statorials.org\/pt\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"caption\":\"Dr. benjamim anderson\"},\"description\":\"Ol\u00e1, sou Benjamin, um professor aposentado de estat\u00edstica que se tornou professor dedicado na Statorials. Com vasta experi\u00eancia e conhecimento na \u00e1rea de estat\u00edstica, estou empenhado em compartilhar meu conhecimento para capacitar os alunos por meio de Statorials. Saber mais\",\"sameAs\":[\"https:\/\/statorials.org\/pt\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Como criar uma s\u00e9rie temporal em R (com exemplos) - Statorials","description":"Este tutorial explica como criar uma s\u00e9rie temporal em R, com v\u00e1rios exemplos.","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\/pt\/criar-series-temporais-em-r\/","og_locale":"pt_PT","og_type":"article","og_title":"Como criar uma s\u00e9rie temporal em R (com exemplos) - Statorials","og_description":"Este tutorial explica como criar uma s\u00e9rie temporal em R, com v\u00e1rios exemplos.","og_url":"https:\/\/statorials.org\/pt\/criar-series-temporais-em-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":"Dr. benjamim anderson","twitter_card":"summary_large_image","twitter_misc":{"Escrito por":"Dr. benjamim anderson","Tempo estimado de leitura":"3 minutos"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/pt\/criar-series-temporais-em-r\/","url":"https:\/\/statorials.org\/pt\/criar-series-temporais-em-r\/","name":"Como criar uma s\u00e9rie temporal em R (com exemplos) - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/pt\/#website"},"datePublished":"2023-07-10T13:48:00+00:00","dateModified":"2023-07-10T13:48:00+00:00","author":{"@id":"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666"},"description":"Este tutorial explica como criar uma s\u00e9rie temporal em R, com v\u00e1rios exemplos.","breadcrumb":{"@id":"https:\/\/statorials.org\/pt\/criar-series-temporais-em-r\/#breadcrumb"},"inLanguage":"pt-PT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/pt\/criar-series-temporais-em-r\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/pt\/criar-series-temporais-em-r\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Lar","item":"https:\/\/statorials.org\/pt\/"},{"@type":"ListItem","position":2,"name":"Como criar uma s\u00e9rie temporal em r (com exemplos)"}]},{"@type":"WebSite","@id":"https:\/\/statorials.org\/pt\/#website","url":"https:\/\/statorials.org\/pt\/","name":"Statorials","description":"O seu guia para a literacia estat\u00edstica!","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/statorials.org\/pt\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"pt-PT"},{"@type":"Person","@id":"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666","name":"Dr. benjamim anderson","image":{"@type":"ImageObject","inLanguage":"pt-PT","@id":"https:\/\/statorials.org\/pt\/#\/schema\/person\/image\/","url":"https:\/\/statorials.org\/pt\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","contentUrl":"https:\/\/statorials.org\/pt\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","caption":"Dr. benjamim anderson"},"description":"Ol\u00e1, sou Benjamin, um professor aposentado de estat\u00edstica que se tornou professor dedicado na Statorials. Com vasta experi\u00eancia e conhecimento na \u00e1rea de estat\u00edstica, estou empenhado em compartilhar meu conhecimento para capacitar os alunos por meio de Statorials. Saber mais","sameAs":["https:\/\/statorials.org\/pt"]}]}},"yoast_meta":{"yoast_wpseo_title":"","yoast_wpseo_metadesc":"","yoast_wpseo_canonical":""},"_links":{"self":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/posts\/4505","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/comments?post=4505"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/posts\/4505\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/media?parent=4505"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/categories?post=4505"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/tags?post=4505"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}