{"id":4460,"date":"2023-07-10T22:52:35","date_gmt":"2023-07-10T22:52:35","guid":{"rendered":"https:\/\/statorials.org\/pt\/r-verifique-se-a-string-contem-varias-substrings\/"},"modified":"2023-07-10T22:52:35","modified_gmt":"2023-07-10T22:52:35","slug":"r-verifique-se-a-string-contem-varias-substrings","status":"publish","type":"post","link":"https:\/\/statorials.org\/pt\/r-verifique-se-a-string-contem-varias-substrings\/","title":{"rendered":"R: verifique se a string cont\u00e9m v\u00e1rias substrings"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Voc\u00ea pode usar os seguintes m\u00e9todos em R para verificar se uma string cont\u00e9m v\u00e1rias substrings:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>M\u00e9todo 1: verifique se a string cont\u00e9m uma das v\u00e1rias substrings<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>df$contains_any &lt;- apply(sapply(find_strings, grepl, df$team), <span style=\"color: #008000;\">1<\/span> , <span style=\"color: #3366ff;\">any<\/span> )\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Esta sintaxe espec\u00edfica verifica se cada string na coluna <strong>team<\/strong> cont\u00e9m <em>uma<\/em> das strings especificadas no vetor de string chamado <strong>find_strings<\/strong> .<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>M\u00e9todo 2: verifique se a string cont\u00e9m v\u00e1rias substrings<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>df$contains_any &lt;- apply(sapply(find_strings, grepl, df$team), <span style=\"color: #008000;\">1<\/span> , <span style=\"color: #3366ff;\">all<\/span> )<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Esta sintaxe espec\u00edfica verifica se cada string na coluna <strong>team<\/strong> cont\u00e9m <i>todas<\/i> as strings especificadas no vetor de string chamado <strong>find_strings<\/strong> .<\/span><\/p>\n<p> <span style=\"color: #000000;\">Os exemplos a seguir mostram como usar cada m\u00e9todo na pr\u00e1tica com o seguinte quadro de dados em R:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #008080;\">#create data frame\n<\/span>df = data. <span style=\"color: #3366ff;\">frame<\/span> (team=c('Good East Team', 'Good West Team', 'Great East Team',\n                       'Great West Team', 'Bad East Team', 'Bad West Team'),\n                points=c(93, 99, 105, 110, 85, 88))\n\n<span style=\"color: #008080;\">#view data frame\n<\/span>df\n\n             team points\n1 Good East Team 93\n2 Good West Team 99\n3 Great East Team 105\n4 Great West Team 110\n5 Bad East Team 85\n6 Bad West Team 88<\/strong><\/span><\/pre>\n<h2> <strong>Exemplo<\/strong> <strong>1: <span style=\"color: #000000;\">Verifique se a string cont\u00e9m uma das v\u00e1rias substrings<\/span><\/strong><\/h2>\n<p> <span style=\"color: #000000;\">Podemos usar a seguinte sintaxe para verificar se cada string na coluna <strong>da equipe<\/strong> cont\u00e9m a substring &#8220;Bom&#8221; <strong>ou<\/strong> &#8220;\u00c9&#8221;:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008080;\">#define substrings to look for\n<\/span>find_strings &lt;- c(' <span style=\"color: #ff0000;\">Good<\/span> ', ' <span style=\"color: #ff0000;\">East<\/span> ')\n\n<span style=\"color: #008080;\">#check if each string in team column contains either substring\n<\/span>df$good_or_east &lt;- apply(sapply(find_strings, grepl, df$team), <span style=\"color: #008000;\">1<\/span> , <span style=\"color: #3366ff;\">any<\/span> )\n\n<span style=\"color: #008080;\">#view updated data frame\n<\/span>df\n\n             team points good_or_east\n1 Good East Team 93 TRUE\n2 Good West Team 99 TRUE\n3 Great East Team 105 TRUE\n4 Great West Team 110 FALSE\n5 Bad East Team 85 TRUE\n6 Bad West Team 88 FALSE<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">A nova coluna <strong>good_or_east<\/strong> retorna os seguintes valores:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\"><b>VERDADEIRO<\/b> se a equipe contiver \u201cBom\u201d ou \u201c\u00c9\u201d<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>FALSO<\/strong> se a equipe n\u00e3o cont\u00e9m nem \u201cBom\u201d nem \u201cLeste\u201d<\/span><\/li>\n<\/ul>\n<h2> <strong>Exemplo 2<\/strong> <strong>: <span style=\"color: #000000;\">Verifique se a string cont\u00e9m v\u00e1rias substrings<\/span><\/strong><\/h2>\n<p> <span style=\"color: #000000;\">Podemos usar a seguinte sintaxe para verificar se cada string na coluna <strong>da equipe<\/strong> cont\u00e9m as substring \u201cBom\u201d <b>e<\/b> \u201cIs\u201d:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008080;\">#define substrings to look for\n<\/span>find_strings &lt;- c(' <span style=\"color: #ff0000;\">Good<\/span> ', ' <span style=\"color: #ff0000;\">East<\/span> ')\n\n<span style=\"color: #008080;\">#check if each string in team column contains either substring\n<\/span>df$good_and_east &lt;- apply(sapply(find_strings, grepl, df$team), <span style=\"color: #008000;\">1<\/span> , <span style=\"color: #3366ff;\">all<\/span> )\n\n<span style=\"color: #008080;\">#view updated data frame\n<\/span>df\n\n             team points good_and_east\n1 Good East Team 93 TRUE\n2 Good West Team 99 FALSE\n3 Great East Team 105 FALSE\n4 Great West Team 110 FALSE\n5 Bad East Team 85 FALSE\n6 Bad West Team 88 FALSE\n<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">A nova coluna <strong>good_and_east<\/strong> retorna os seguintes valores:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\"><b>VERDADEIRO<\/b> se a equipe contiver \u201cBom\u201d e \u201c\u00c9\u201d<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>FALSO<\/strong> se a equipe n\u00e3o cont\u00e9m \u201cBom\u201d e \u201c\u00c9\u201d<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">Observe que apenas um valor <b>TRUE<\/b> \u00e9 retornado, pois h\u00e1 apenas um nome de equipe contendo a substring &#8220;Boa&#8221; <strong>e<\/strong> a substring &#8220;Leste&#8221;.<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Recursos adicionais<\/strong><\/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\/r-verifique-se-o-caractere-na-string\/\" target=\"_blank\" rel=\"noopener\">R: Como verificar se o caractere est\u00e1 em uma string<\/a><br \/> <a href=\"https:\/\/statorials.org\/pt\/r-remova-espacos-da-string\/\" target=\"_blank\" rel=\"noopener\">R: Como remover espa\u00e7os de strings<\/a><br \/> <a href=\"https:\/\/statorials.org\/pt\/r-extrai-string-entre-caracteres\/\" target=\"_blank\" rel=\"noopener\">A: Como extrair uma string entre caracteres espec\u00edficos<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Voc\u00ea pode usar os seguintes m\u00e9todos em R para verificar se uma string cont\u00e9m v\u00e1rias substrings: M\u00e9todo 1: verifique se a string cont\u00e9m uma das v\u00e1rias substrings df$contains_any &lt;- apply(sapply(find_strings, grepl, df$team), 1 , any ) Esta sintaxe espec\u00edfica verifica se cada string na coluna team cont\u00e9m uma das strings especificadas no vetor de string [&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-4460","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>A: Verifique se a string cont\u00e9m m\u00faltiplas substrings \u2013 Estatologia<\/title>\n<meta name=\"description\" content=\"Este tutorial explica como verificar se uma string cont\u00e9m m\u00faltiplas substrings 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\/r-verifique-se-a-string-contem-varias-substrings\/\" \/>\n<meta property=\"og:locale\" content=\"pt_PT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"A: Verifique se a string cont\u00e9m m\u00faltiplas substrings \u2013 Estatologia\" \/>\n<meta property=\"og:description\" content=\"Este tutorial explica como verificar se uma string cont\u00e9m m\u00faltiplas substrings em R, com v\u00e1rios exemplos.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/pt\/r-verifique-se-a-string-contem-varias-substrings\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-10T22:52:35+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=\"3 minutos\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/pt\/r-verifique-se-a-string-contem-varias-substrings\/\",\"url\":\"https:\/\/statorials.org\/pt\/r-verifique-se-a-string-contem-varias-substrings\/\",\"name\":\"A: Verifique se a string cont\u00e9m m\u00faltiplas substrings \u2013 Estatologia\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/pt\/#website\"},\"datePublished\":\"2023-07-10T22:52:35+00:00\",\"dateModified\":\"2023-07-10T22:52:35+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666\"},\"description\":\"Este tutorial explica como verificar se uma string cont\u00e9m m\u00faltiplas substrings em R, com v\u00e1rios exemplos.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/pt\/r-verifique-se-a-string-contem-varias-substrings\/#breadcrumb\"},\"inLanguage\":\"pt-PT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/pt\/r-verifique-se-a-string-contem-varias-substrings\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/pt\/r-verifique-se-a-string-contem-varias-substrings\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Lar\",\"item\":\"https:\/\/statorials.org\/pt\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"R: verifique se a string cont\u00e9m v\u00e1rias substrings\"}]},{\"@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":"A: Verifique se a string cont\u00e9m m\u00faltiplas substrings \u2013 Estatologia","description":"Este tutorial explica como verificar se uma string cont\u00e9m m\u00faltiplas substrings 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\/r-verifique-se-a-string-contem-varias-substrings\/","og_locale":"pt_PT","og_type":"article","og_title":"A: Verifique se a string cont\u00e9m m\u00faltiplas substrings \u2013 Estatologia","og_description":"Este tutorial explica como verificar se uma string cont\u00e9m m\u00faltiplas substrings em R, com v\u00e1rios exemplos.","og_url":"https:\/\/statorials.org\/pt\/r-verifique-se-a-string-contem-varias-substrings\/","og_site_name":"Statorials","article_published_time":"2023-07-10T22:52:35+00:00","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\/r-verifique-se-a-string-contem-varias-substrings\/","url":"https:\/\/statorials.org\/pt\/r-verifique-se-a-string-contem-varias-substrings\/","name":"A: Verifique se a string cont\u00e9m m\u00faltiplas substrings \u2013 Estatologia","isPartOf":{"@id":"https:\/\/statorials.org\/pt\/#website"},"datePublished":"2023-07-10T22:52:35+00:00","dateModified":"2023-07-10T22:52:35+00:00","author":{"@id":"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666"},"description":"Este tutorial explica como verificar se uma string cont\u00e9m m\u00faltiplas substrings em R, com v\u00e1rios exemplos.","breadcrumb":{"@id":"https:\/\/statorials.org\/pt\/r-verifique-se-a-string-contem-varias-substrings\/#breadcrumb"},"inLanguage":"pt-PT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/pt\/r-verifique-se-a-string-contem-varias-substrings\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/pt\/r-verifique-se-a-string-contem-varias-substrings\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Lar","item":"https:\/\/statorials.org\/pt\/"},{"@type":"ListItem","position":2,"name":"R: verifique se a string cont\u00e9m v\u00e1rias substrings"}]},{"@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\/4460","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=4460"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/posts\/4460\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/media?parent=4460"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/categories?post=4460"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/tags?post=4460"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}