{"id":1789,"date":"2023-07-24T23:38:42","date_gmt":"2023-07-24T23:38:42","guid":{"rendered":"https:\/\/statorials.org\/pt\/str_split-em-r\/"},"modified":"2023-07-24T23:38:42","modified_gmt":"2023-07-24T23:38:42","slug":"str_split-em-r","status":"publish","type":"post","link":"https:\/\/statorials.org\/pt\/str_split-em-r\/","title":{"rendered":"Como usar str_split em r (com exemplos)"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">A fun\u00e7\u00e3o <strong>str_split()<\/strong> do pacote <a href=\"https:\/\/stringr.tidyverse.org\/\" target=\"_blank\" rel=\"noopener\">stringr<\/a> em R pode ser usada para dividir uma string em v\u00e1rios peda\u00e7os. Esta fun\u00e7\u00e3o usa a seguinte sintaxe:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>str_split(string, padr\u00e3o)<\/strong><\/span><\/p>\n<p> <span style=\"color: #000000;\">Ouro:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\"><strong>string:<\/strong> vetor de caracteres<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>padr\u00e3o:<\/strong> padr\u00e3o no qual dividir<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">Da mesma forma, a fun\u00e7\u00e3o <strong>str_split_fixed()<\/strong> do pacote stringr pode ser usada para dividir uma string em um n\u00famero fixo de peda\u00e7os. Esta fun\u00e7\u00e3o usa a seguinte sintaxe:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>str_split_fixed(string, padr\u00e3o, n)<\/strong><\/span><\/p>\n<p> <span style=\"color: #000000;\">Ouro:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\"><strong>string:<\/strong> vetor de caracteres<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>padr\u00e3o:<\/strong> padr\u00e3o no qual dividir<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>n:<\/strong> N\u00famero de pe\u00e7as a serem devolvidas<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">Este tutorial fornece exemplos de uso de cada uma dessas fun\u00e7\u00f5es no seguinte quadro de dados:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#create data frame<\/span>\ndf &lt;- data. <span style=\"color: #3366ff;\">frame<\/span> (team=c('andy &amp; bob', 'carl &amp; doug', 'eric &amp; frank'),\n                 dots=c(14, 17, 19))\n\n<span style=\"color: #008080;\">#view data frame\n<\/span>df\n\n          team points\n1 andy &amp; bob 14\n2 carl &amp; doug 17\n3 eric &amp; frank 19\n<\/strong><\/pre>\n<h3> <strong><span style=\"color: #000000;\">Exemplo 1: Dividir uma String Usando str_split()<\/span><\/strong><\/h3>\n<p> <span style=\"color: #000000;\">O c\u00f3digo a seguir mostra como dividir a string na coluna \u201cteam\u201d usando a fun\u00e7\u00e3o <strong>str_split()<\/strong> :<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #993300;\">library<\/span> (stringr)<\/span>\n\n<\/span><span style=\"color: #008080;\">#split the string in the <em>team<\/em> column on \" &amp; \"\n<\/span>str_split(df$team, \" &amp; \")\n\n[[1]]\n[1] \u201candy\u201d \u201cbob\u201d \n\n[[2]]\n[1] \u201ccarl\u201d \u201cdoug\u201d\n\n[[3]]\n[1] \u201ceric\u201d \u201cfrank\u201d<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">O resultado \u00e9 uma lista de tr\u00eas itens que mostram os nomes dos jogadores individuais de cada equipe.<\/span><\/p>\n<h3> <strong><span style=\"color: #000000;\">Exemplo 2:<\/span><\/strong> <strong><span style=\"color: #000000;\">Dividir uma string usando str_split_fixed()<\/span><\/strong><\/h3>\n<p> <span style=\"color: #000000;\">O c\u00f3digo a seguir mostra como dividir a string na coluna \u201cteam\u201d em duas partes fixas usando a fun\u00e7\u00e3o <strong>str_split_fixed()<\/strong> :<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #993300;\">library<\/span> (stringr)\n\n<span style=\"color: #008080;\">#split the string in the <em>team<\/em> column on \" &amp; \"<\/span>\nstr_split_fixed(df$team, \" &amp; \", 2)\n\n     [,1] [,2]   \n[1,] \u201candy\u201d \u201cbob\u201d  \n[2,] \"carl\" \"doug\" \n[3,] \"eric\" \"frank\"<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">O resultado \u00e9 uma matriz com duas colunas e tr\u00eas linhas.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Uma aplica\u00e7\u00e3o \u00fatil da fun\u00e7\u00e3o <strong>str_split_fixed()<\/strong> \u00e9 anexar a matriz resultante ao final do quadro de dados. Por exemplo:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #993300;\">library<\/span> (stringr)\n\n<span style=\"color: #008080;\">#split the string in the <em>team<\/em> column and append resulting matrix to data frame\n<\/span>df[, 3:4] &lt;- str_split_fixed(df$team, \" &amp; \", 2)\n\n<span style=\"color: #008080;\">#view data frame<\/span>\ndf\n          team points V3 V4\n1 andy &amp; bob 14 andy bob\n2 carl &amp; doug 17 carl doug\n3 eric &amp; frank 19 eric frank<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">A coluna denominada \u201cV3\u201d exibe o nome do primeiro jogador da equipe e a coluna denominada \u201cV4\u201d exibe o nome do segundo jogador da equipe.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Recursos adicionais<\/strong><\/span><\/h3>\n<p> <a href=\"https:\/\/statorials.org\/pt\/str_replace-em-r\/\" target=\"_blank\" rel=\"noopener\">Como usar str_replace em R<\/a><br \/> Como realizar correspond\u00eancia parcial de strings em R<br \/><a href=\"https:\/\/statorials.org\/pt\/converter-strings-em-datas-em-r\/\" target=\"_blank\" rel=\"noopener\">Como converter strings em datas em R<\/a><br \/> <a href=\"https:\/\/statorials.org\/pt\/caractere-numerico-em-r\/\" target=\"_blank\" rel=\"noopener\">Como converter caractere em num\u00e9rico em R<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>A fun\u00e7\u00e3o str_split() do pacote stringr em R pode ser usada para dividir uma string em v\u00e1rios peda\u00e7os. Esta fun\u00e7\u00e3o usa a seguinte sintaxe: str_split(string, padr\u00e3o) Ouro: string: vetor de caracteres padr\u00e3o: padr\u00e3o no qual dividir Da mesma forma, a fun\u00e7\u00e3o str_split_fixed() do pacote stringr pode ser usada para dividir uma string em um n\u00famero [&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-1789","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 str_split em R (com exemplos) \u2013 Estatoriais<\/title>\n<meta name=\"description\" content=\"Este tutorial explica como usar a fun\u00e7\u00e3o str_split 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\/str_split-em-r\/\" \/>\n<meta property=\"og:locale\" content=\"pt_PT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Como usar str_split em R (com exemplos) \u2013 Estatoriais\" \/>\n<meta property=\"og:description\" content=\"Este tutorial explica como usar a fun\u00e7\u00e3o str_split em R, com v\u00e1rios exemplos.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/pt\/str_split-em-r\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-24T23:38:42+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\/str_split-em-r\/\",\"url\":\"https:\/\/statorials.org\/pt\/str_split-em-r\/\",\"name\":\"Como usar str_split em R (com exemplos) \u2013 Estatoriais\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/pt\/#website\"},\"datePublished\":\"2023-07-24T23:38:42+00:00\",\"dateModified\":\"2023-07-24T23:38:42+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666\"},\"description\":\"Este tutorial explica como usar a fun\u00e7\u00e3o str_split em R, com v\u00e1rios exemplos.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/pt\/str_split-em-r\/#breadcrumb\"},\"inLanguage\":\"pt-PT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/pt\/str_split-em-r\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/pt\/str_split-em-r\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Lar\",\"item\":\"https:\/\/statorials.org\/pt\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Como usar str_split 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 usar str_split em R (com exemplos) \u2013 Estatoriais","description":"Este tutorial explica como usar a fun\u00e7\u00e3o str_split 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\/str_split-em-r\/","og_locale":"pt_PT","og_type":"article","og_title":"Como usar str_split em R (com exemplos) \u2013 Estatoriais","og_description":"Este tutorial explica como usar a fun\u00e7\u00e3o str_split em R, com v\u00e1rios exemplos.","og_url":"https:\/\/statorials.org\/pt\/str_split-em-r\/","og_site_name":"Statorials","article_published_time":"2023-07-24T23:38:42+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\/str_split-em-r\/","url":"https:\/\/statorials.org\/pt\/str_split-em-r\/","name":"Como usar str_split em R (com exemplos) \u2013 Estatoriais","isPartOf":{"@id":"https:\/\/statorials.org\/pt\/#website"},"datePublished":"2023-07-24T23:38:42+00:00","dateModified":"2023-07-24T23:38:42+00:00","author":{"@id":"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666"},"description":"Este tutorial explica como usar a fun\u00e7\u00e3o str_split em R, com v\u00e1rios exemplos.","breadcrumb":{"@id":"https:\/\/statorials.org\/pt\/str_split-em-r\/#breadcrumb"},"inLanguage":"pt-PT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/pt\/str_split-em-r\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/pt\/str_split-em-r\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Lar","item":"https:\/\/statorials.org\/pt\/"},{"@type":"ListItem","position":2,"name":"Como usar str_split 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\/1789","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=1789"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/posts\/1789\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/media?parent=1789"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/categories?post=1789"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/tags?post=1789"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}