{"id":4462,"date":"2023-07-10T22:52:35","date_gmt":"2023-07-10T22:52:35","guid":{"rendered":"https:\/\/statorials.org\/it\/r-controlla-se-la-stringa-contiene-piu-sottostringhe\/"},"modified":"2023-07-10T22:52:35","modified_gmt":"2023-07-10T22:52:35","slug":"r-controlla-se-la-stringa-contiene-piu-sottostringhe","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/r-controlla-se-la-stringa-contiene-piu-sottostringhe\/","title":{"rendered":"A: controlla se la stringa contiene pi\u00f9 sottostringhe"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">\u00c8 possibile utilizzare i seguenti metodi in R per verificare se una stringa contiene pi\u00f9 sottostringhe:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Metodo 1: controlla se la stringa contiene una delle diverse sottostringhe<\/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;\">Questa particolare sintassi controlla se ogni stringa nella colonna del <strong>team<\/strong> contiene <em>una<\/em> delle stringhe specificate nel vettore di stringhe chiamato <strong>find_strings<\/strong> .<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Metodo 2: controlla se la stringa contiene pi\u00f9 sottostringhe<\/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;\">Questa particolare sintassi controlla se ogni stringa nella colonna del <strong>team<\/strong> contiene <i>tutte<\/i> le stringhe specificate nel vettore di stringhe chiamato <strong>find_strings<\/strong> .<\/span><\/p>\n<p> <span style=\"color: #000000;\">I seguenti esempi mostrano come utilizzare ciascun metodo nella pratica con il seguente frame di dati in 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>Esempio<\/strong> <strong>1: <span style=\"color: #000000;\">controlla se la stringa contiene una delle diverse sottostringhe<\/span><\/strong><\/h2>\n<p> <span style=\"color: #000000;\">Possiamo utilizzare la seguente sintassi per verificare se ogni stringa nella colonna <strong>del team<\/strong> contiene la sottostringa &#8220;Buono&#8221; <strong>o<\/strong> &#8220;\u00c8&#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;\">La nuova colonna <strong>good_or_east<\/strong> restituisce i seguenti valori:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\"><b>VERO<\/b> se la squadra contiene \u201cBuono\u201d o \u201c\u00c8\u201d<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>FALSO<\/strong> se la squadra non contiene n\u00e9 \u201cBuono\u201d n\u00e9 \u201cEst\u201d<\/span><\/li>\n<\/ul>\n<h2> <strong>Esempio 2<\/strong> <strong>: <span style=\"color: #000000;\">controlla se la stringa contiene pi\u00f9 sottostringhe<\/span><\/strong><\/h2>\n<p> <span style=\"color: #000000;\">Possiamo utilizzare la seguente sintassi per verificare se ogni stringa nella colonna <strong>team<\/strong> contiene la sottostringa \u201cBuono\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;\">La nuova colonna <strong>good_and_east<\/strong> restituisce i seguenti valori:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\"><b>VERO<\/b> se la squadra contiene \u201cBuono\u201d e \u201c\u00c8\u201d<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>FALSO<\/strong> se la squadra non contiene \u201cBuono\u201d e \u201c\u00c8\u201d<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">Tieni presente che viene restituito un solo valore <b>VERO<\/b> poich\u00e9 esiste un solo nome di squadra contenente la sottostringa &#8220;Buono&#8221; <strong>e<\/strong> la sottostringa &#8220;Est&#8221;.<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Risorse addizionali<\/strong><\/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\/r-controlla-se-il-carattere-e-nella-stringa\/\" target=\"_blank\" rel=\"noopener\">A: Come verificare se il carattere \u00e8 in una stringa<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/r-rimuovi-gli-spazi-dalla-stringa\/\" target=\"_blank\" rel=\"noopener\">A: Come rimuovere gli spazi dalle stringhe<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/r-estrae-la-stringa-tra-i-caratteri\/\" target=\"_blank\" rel=\"noopener\">A: Come estrarre una stringa tra caratteri specifici<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u00c8 possibile utilizzare i seguenti metodi in R per verificare se una stringa contiene pi\u00f9 sottostringhe: Metodo 1: controlla se la stringa contiene una delle diverse sottostringhe df$contains_any &lt;- apply(sapply(find_strings, grepl, df$team), 1 , any ) Questa particolare sintassi controlla se ogni stringa nella colonna del team contiene una delle stringhe specificate nel vettore di [&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>A: Controlla se la stringa contiene pi\u00f9 sottostringhe \u2013 Statorials<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come verificare se una stringa contiene pi\u00f9 sottostringhe 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\/r-controlla-se-la-stringa-contiene-piu-sottostringhe\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"A: Controlla se la stringa contiene pi\u00f9 sottostringhe \u2013 Statorials\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come verificare se una stringa contiene pi\u00f9 sottostringhe in R, con diversi esempi.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/r-controlla-se-la-stringa-contiene-piu-sottostringhe\/\" \/>\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=\"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=\"2 minuti\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/it\/r-controlla-se-la-stringa-contiene-piu-sottostringhe\/\",\"url\":\"https:\/\/statorials.org\/it\/r-controlla-se-la-stringa-contiene-piu-sottostringhe\/\",\"name\":\"A: Controlla se la stringa contiene pi\u00f9 sottostringhe \u2013 Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-10T22:52:35+00:00\",\"dateModified\":\"2023-07-10T22:52:35+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come verificare se una stringa contiene pi\u00f9 sottostringhe in R, con diversi esempi.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/r-controlla-se-la-stringa-contiene-piu-sottostringhe\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/r-controlla-se-la-stringa-contiene-piu-sottostringhe\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/r-controlla-se-la-stringa-contiene-piu-sottostringhe\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"A: controlla se la stringa contiene pi\u00f9 sottostringhe\"}]},{\"@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":"A: Controlla se la stringa contiene pi\u00f9 sottostringhe \u2013 Statorials","description":"Questo tutorial spiega come verificare se una stringa contiene pi\u00f9 sottostringhe 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\/r-controlla-se-la-stringa-contiene-piu-sottostringhe\/","og_locale":"it_IT","og_type":"article","og_title":"A: Controlla se la stringa contiene pi\u00f9 sottostringhe \u2013 Statorials","og_description":"Questo tutorial spiega come verificare se una stringa contiene pi\u00f9 sottostringhe in R, con diversi esempi.","og_url":"https:\/\/statorials.org\/it\/r-controlla-se-la-stringa-contiene-piu-sottostringhe\/","og_site_name":"Statorials","article_published_time":"2023-07-10T22:52:35+00:00","author":"Benjamin anderson","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Benjamin anderson","Est. reading time":"2 minuti"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/it\/r-controlla-se-la-stringa-contiene-piu-sottostringhe\/","url":"https:\/\/statorials.org\/it\/r-controlla-se-la-stringa-contiene-piu-sottostringhe\/","name":"A: Controlla se la stringa contiene pi\u00f9 sottostringhe \u2013 Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-10T22:52:35+00:00","dateModified":"2023-07-10T22:52:35+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come verificare se una stringa contiene pi\u00f9 sottostringhe in R, con diversi esempi.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/r-controlla-se-la-stringa-contiene-piu-sottostringhe\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/r-controlla-se-la-stringa-contiene-piu-sottostringhe\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/r-controlla-se-la-stringa-contiene-piu-sottostringhe\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"A: controlla se la stringa contiene pi\u00f9 sottostringhe"}]},{"@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\/4462"}],"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=4462"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/4462\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=4462"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=4462"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=4462"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}