{"id":2901,"date":"2023-07-20T04:29:07","date_gmt":"2023-07-20T04:29:07","guid":{"rendered":"https:\/\/statorials.org\/pt\/strptime-strftime-r\/"},"modified":"2023-07-20T04:29:07","modified_gmt":"2023-07-20T04:29:07","slug":"strptime-strftime-r","status":"publish","type":"post","link":"https:\/\/statorials.org\/pt\/strptime-strftime-r\/","title":{"rendered":"Como usar as fun\u00e7\u00f5es strptime e strftime em r"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Voc\u00ea pode usar as fun\u00e7\u00f5es <strong>strptime<\/strong> e <strong>strftime<\/strong> em R para converter entre objetos de caractere e tempo.<\/span><\/p>\n<p> <span style=\"color: #000000;\">A fun\u00e7\u00e3o <strong>strptime<\/strong> converte caracteres em objetos de hora e usa a seguinte sintaxe b\u00e1sica:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\">strptime(character_object, format=\" <span style=\"color: #ff0000;\">%Y-%m-%d<\/span> \")<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">A fun\u00e7\u00e3o <strong>strftime<\/strong> converte objetos de hora em caracteres e usa a seguinte sintaxe b\u00e1sica:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\">strftime(time_object)<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Os exemplos a seguir mostram como usar cada fun\u00e7\u00e3o na pr\u00e1tica.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Exemplo 1: Use a fun\u00e7\u00e3o strptime em R<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Suponha que temos o seguinte vetor de caracteres em R:<\/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 character vector\n<\/span>char_data &lt;- c(\"2022-01-01\", \"2022-01-25\", \"2022-02-14\", \"2022-03-19\")\n\n<span style=\"color: #008080;\">#view class of vector\n<\/span>class(char_data)\n\n[1] \u201ccharacter\u201d\n<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Podemos usar a fun\u00e7\u00e3o <strong>strptime<\/strong> para converter caracteres em objetos de tempo:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008080;\">#convert characters to time objects\n<\/span>time_data &lt;- strptime(char_data, format=\" <span style=\"color: #ff0000;\">%Y-%m-%d<\/span> \")\n\n<span style=\"color: #008080;\">#view new vector\n<\/span>time_data\n\n[1] \"2022-01-01 UTC\" \"2022-01-25 UTC\" \"2022-02-14 UTC\" \"2022-03-19 UTC\"\n\n<span style=\"color: #008080;\">#view class of new vector\n<\/span>class(time_data)\n\n[1] \u201cPOSIXlt\u201d \u201cPOSIXt\u201d\n<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Pode-se observar que os personagens foram convertidos em objetos temporais.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Observe que tamb\u00e9m podemos usar o argumento <strong>tz<\/strong> para converter caracteres em objetos de hora com um fuso hor\u00e1rio espec\u00edfico.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Por exemplo, poder\u00edamos especificar &#8220;EST&#8221; para converter caracteres em objetos de hora no fuso hor\u00e1rio do Leste:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008080;\">#convert characters to time objects in EST time zone\n<\/span>time_data &lt;- strptime(char_data, format=\" <span style=\"color: #ff0000;\">%Y-%m-%d<\/span> \", tz=\" <span style=\"color: #ff0000;\">IS<\/span> \")\n\n<span style=\"color: #008080;\">#view new vector\n<\/span>time_data\n\n[1] \"2022-01-01 EST\" \"2022-01-25 EST\" \"2022-02-14 EST\" \"2022-03-19 EST\"\n<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Observe que cada um dos objetos de hor\u00e1rio agora termina em <strong>EST<\/strong> , o que indica um fuso hor\u00e1rio do Leste.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Exemplo 2: Use a fun\u00e7\u00e3o strftime em R<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Suponha que temos o seguinte vetor de objetos temporais em R:<\/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 vector of time objects\n<\/span>time_data &lt;- as. <span style=\"color: #3366ff;\">POSIXct<\/span> (c(\"2022-01-01\", \"2022-01-25\", \"2022-02-14\"))\n\n<span style=\"color: #008080;\">#view class of vector\n<\/span>class(time_data)\n\n[1] \u201cPOSIXct\u201d \u201cPOSIXt\u201d\n<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Podemos usar a fun\u00e7\u00e3o <strong>strftime<\/strong> para converter objetos de tempo em caracteres:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008080;\">#convert time objects to characters\n<\/span>char_data &lt;- strftime(time_data)\n\n<span style=\"color: #008080;\">#view new vector\n<\/span>char_data\n\n[1] \"2022-01-01\" \"2022-01-25\" \"2022-02-14\"\n\n<span style=\"color: #008080;\">#view class of new vector\n<\/span>class(char_data)\n\n[1] \u201ccharacter\u201d\n<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Vemos que os objetos temporais foram convertidos em personagens.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Recursos adicionais<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Os tutoriais a seguir explicam como usar outras fun\u00e7\u00f5es comuns em R:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/pt\/funcao-de-tabulacao-em-r\/\" target=\"_blank\" rel=\"noopener\">Como usar a fun\u00e7\u00e3o tabulate() em R<\/a><br \/> <a href=\"https:\/\/statorials.org\/pt\/funcao-de-divisao-em-r\/\" target=\"_blank\" rel=\"noopener\">Como usar a fun\u00e7\u00e3o split() em R<\/a><br \/> <a href=\"https:\/\/statorials.org\/pt\/funcao-de-correspondencia-em-r\/\" target=\"_blank\" rel=\"noopener\">Como usar a fun\u00e7\u00e3o match() em R<\/a><br \/> <a href=\"https:\/\/statorials.org\/pt\/replicar-funcao-em-r\/\" target=\"_blank\" rel=\"noopener\">Como usar a fun\u00e7\u00e3o replicate() em R<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Voc\u00ea pode usar as fun\u00e7\u00f5es strptime e strftime em R para converter entre objetos de caractere e tempo. A fun\u00e7\u00e3o strptime converte caracteres em objetos de hora e usa a seguinte sintaxe b\u00e1sica: strptime(character_object, format=&#8221; %Y-%m-%d &#8220;) A fun\u00e7\u00e3o strftime converte objetos de hora em caracteres e usa a seguinte sintaxe b\u00e1sica: strftime(time_object) Os exemplos [&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-2901","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 usar as fun\u00e7\u00f5es strptime e strftime em R - Estatologia<\/title>\n<meta name=\"description\" content=\"Este tutorial explica como usar as fun\u00e7\u00f5es strptime e strftime 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\/strptime-strftime-r\/\" \/>\n<meta property=\"og:locale\" content=\"pt_PT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Como usar as fun\u00e7\u00f5es strptime e strftime em R - Estatologia\" \/>\n<meta property=\"og:description\" content=\"Este tutorial explica como usar as fun\u00e7\u00f5es strptime e strftime em R, com v\u00e1rios exemplos.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/pt\/strptime-strftime-r\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-20T04:29:07+00:00\" \/>\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=\"2 minutos\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/pt\/strptime-strftime-r\/\",\"url\":\"https:\/\/statorials.org\/pt\/strptime-strftime-r\/\",\"name\":\"Como usar as fun\u00e7\u00f5es strptime e strftime em R - Estatologia\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/pt\/#website\"},\"datePublished\":\"2023-07-20T04:29:07+00:00\",\"dateModified\":\"2023-07-20T04:29:07+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666\"},\"description\":\"Este tutorial explica como usar as fun\u00e7\u00f5es strptime e strftime em R, com v\u00e1rios exemplos.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/pt\/strptime-strftime-r\/#breadcrumb\"},\"inLanguage\":\"pt-PT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/pt\/strptime-strftime-r\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/pt\/strptime-strftime-r\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Lar\",\"item\":\"https:\/\/statorials.org\/pt\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Como usar as fun\u00e7\u00f5es strptime e strftime em r\"}]},{\"@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 usar as fun\u00e7\u00f5es strptime e strftime em R - Estatologia","description":"Este tutorial explica como usar as fun\u00e7\u00f5es strptime e strftime 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\/strptime-strftime-r\/","og_locale":"pt_PT","og_type":"article","og_title":"Como usar as fun\u00e7\u00f5es strptime e strftime em R - Estatologia","og_description":"Este tutorial explica como usar as fun\u00e7\u00f5es strptime e strftime em R, com v\u00e1rios exemplos.","og_url":"https:\/\/statorials.org\/pt\/strptime-strftime-r\/","og_site_name":"Statorials","article_published_time":"2023-07-20T04:29:07+00:00","author":"Dr. benjamim anderson","twitter_card":"summary_large_image","twitter_misc":{"Escrito por":"Dr. benjamim anderson","Tempo estimado de leitura":"2 minutos"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/pt\/strptime-strftime-r\/","url":"https:\/\/statorials.org\/pt\/strptime-strftime-r\/","name":"Como usar as fun\u00e7\u00f5es strptime e strftime em R - Estatologia","isPartOf":{"@id":"https:\/\/statorials.org\/pt\/#website"},"datePublished":"2023-07-20T04:29:07+00:00","dateModified":"2023-07-20T04:29:07+00:00","author":{"@id":"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666"},"description":"Este tutorial explica como usar as fun\u00e7\u00f5es strptime e strftime em R, com v\u00e1rios exemplos.","breadcrumb":{"@id":"https:\/\/statorials.org\/pt\/strptime-strftime-r\/#breadcrumb"},"inLanguage":"pt-PT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/pt\/strptime-strftime-r\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/pt\/strptime-strftime-r\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Lar","item":"https:\/\/statorials.org\/pt\/"},{"@type":"ListItem","position":2,"name":"Como usar as fun\u00e7\u00f5es strptime e strftime em r"}]},{"@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\/2901","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=2901"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/posts\/2901\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/media?parent=2901"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/categories?post=2901"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/tags?post=2901"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}