{"id":953,"date":"2023-07-28T04:57:15","date_gmt":"2023-07-28T04:57:15","guid":{"rendered":"https:\/\/statorials.org\/pl\/grep-kontra-grepl-r\/"},"modified":"2023-07-28T04:57:15","modified_gmt":"2023-07-28T04:57:15","slug":"grep-kontra-grepl-r","status":"publish","type":"post","link":"https:\/\/statorials.org\/pl\/grep-kontra-grepl-r\/","title":{"rendered":"Por\u00f3wnanie grep() i grepl() w r: jaka jest r\u00f3\u017cnica?"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Dwie funkcje, kt\u00f3re ludzie cz\u0119sto myl\u0105 w R, to <strong>grep()<\/strong> i <strong>grepl()<\/strong> . Obie funkcje pozwalaj\u0105 sprawdzi\u0107, czy w ci\u0105gu znak\u00f3w istnieje okre\u015blony wzorzec, ale zwracaj\u0105 r\u00f3\u017cne wyniki:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\"><strong>grepl()<\/strong> zwraca warto\u015b\u0107 PRAWDA, je\u015bli w ci\u0105gu znak\u00f3w istnieje wzorzec.<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>grep()<\/strong> zwraca wektor indeks\u00f3w \u0142a\u0144cuchowych zawieraj\u0105cych wzorzec.<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">Poni\u017cszy przyk\u0142ad ilustruje t\u0119 r\u00f3\u017cnic\u0119:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#create a vector of data<\/span>\ndata &lt;- c('P Guard', 'S Guard', 'S Forward', 'P Forward', 'Center')\n\n<span style=\"color: #3366ff;\">grep<\/span> ('Guard', data)\n[1] 1 2\n\n<span style=\"color: #3366ff;\">grepl<\/span> ('Guard', data) \n[1] TRUE TRUE FALSE FALSE FALSE<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Poni\u017csze przyk\u0142ady pokazuj\u0105, kiedy mo\u017cesz chcie\u0107 u\u017cy\u0107 jednej z tych funkcji zamiast drugiej.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Kiedy u\u017cywa\u0107 grepl()<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\"><strong>1. Filtruj wiersze zawieraj\u0105ce okre\u015blony ci\u0105g<\/strong><\/span><\/p>\n<p> <span style=\"color: #000000;\">Jednym z najcz\u0119stszych zastosowa\u0144 <strong>grepl()<\/strong> jest filtrowanie wierszy w ramce danych zawieraj\u0105cej okre\u015blony ci\u0105g znak\u00f3w:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\">library(dplyr)<\/span>\n\n#create data frame<\/span>\ndf &lt;- data.frame(player = c('P Guard', 'S Guard', 'S Forward', 'P Forward', 'Center'),\n                 points = c(12, 15, 19, 22, 32),\n                 rebounds = c(5, 7, 7, 12, 11))\n\n<span style=\"color: #008080;\">#filter rows that contain the string 'Guard' in the player column\n<\/span><span style=\"color: #000000;\">df %&gt;% filter( <span style=\"color: #3366ff;\">grepl<\/span> ('Guard', player))\n\n   player points rebounds\n1 P Guard 12 5\n2 S Guard 15 7<\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\"><strong>Powi\u0105zane:<\/strong> <a href=\"https:\/\/statorials.org\/pl\/filtruj-linie-zawierajace-ciag-dplyr\/\">Jak filtrowa\u0107 wiersze zawieraj\u0105ce okre\u015blony ci\u0105g za pomoc\u0105 dplyr<\/a><\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Kiedy u\u017cywa\u0107 grep()<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\"><strong>1. Wybierz kolumny zawieraj\u0105ce okre\u015blony ci\u0105g<\/strong><\/span><\/p>\n<p> <span style=\"color: #000000;\">Mo\u017cesz u\u017cy\u0107 <strong>grep()<\/strong> , aby wybra\u0107 kolumny w ramce danych zawieraj\u0105cej okre\u015blony ci\u0105g:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\">library(dplyr)<\/span>\n\n#create data frame<\/span>\ndf &lt;- data.frame(player = c('P Guard', 'S Guard', 'S Forward', 'P Forward', 'Center'),\n                 points = c(12, 15, 19, 22, 32),\n                 rebounds = c(5, 7, 7, 12, 11))\n\n<span style=\"color: #008080;\">#select columns that contain the string 'p' in their name\n<\/span><span style=\"color: #000000;\">df %&gt;% select( <span style=\"color: #3366ff;\">grep<\/span> ('p', colnames(df)))\n\n     player points\n1 P Guard 12\n2 S Guard 15\n3S Forward 19\n4P Forward 22\n5 Center 32<\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\"><strong>2. Policz liczb\u0119 linii zawieraj\u0105cych okre\u015blony ci\u0105g<\/strong><\/span><\/p>\n<p> <span style=\"color: #000000;\">Mo\u017cesz u\u017cy\u0107 <strong>grep()<\/strong> do zliczenia liczby linii w ramce danych zawieraj\u0105cej okre\u015blony ci\u0105g:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#create data frame<\/span>\ndf &lt;- data.frame(player = c('P Guard', 'S Guard', 'S Forward', 'P Forward', 'Center'),\n                 points = c(12, 15, 19, 22, 32),\n                 rebounds = c(5, 7, 7, 12, 11))\n\n<span style=\"color: #008080;\">#count how many rows contain the string 'Guard' in the player column\n<\/span><span style=\"color: #000000;\">length( <span style=\"color: #3366ff;\">grep<\/span> ('Guard', df$player))\n\n[1] 2<\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\"><em>Wi\u0119cej samouczk\u00f3w dotycz\u0105cych j\u0119zyka R mo\u017cna znale\u017a\u0107 <a href=\"https:\/\/statorials.org\" target=\"_blank\" rel=\"noopener noreferrer\">tutaj<\/a> .<\/em><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Dwie funkcje, kt\u00f3re ludzie cz\u0119sto myl\u0105 w R, to grep() i grepl() . Obie funkcje pozwalaj\u0105 sprawdzi\u0107, czy w ci\u0105gu znak\u00f3w istnieje okre\u015blony wzorzec, ale zwracaj\u0105 r\u00f3\u017cne wyniki: grepl() zwraca warto\u015b\u0107 PRAWDA, je\u015bli w ci\u0105gu znak\u00f3w istnieje wzorzec. grep() zwraca wektor indeks\u00f3w \u0142a\u0144cuchowych zawieraj\u0105cych wzorzec. Poni\u017cszy przyk\u0142ad ilustruje t\u0119 r\u00f3\u017cnic\u0119: #create a vector of data [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-953","post","type-post","status-publish","format-standard","hentry","category-przewodnik"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Por\u00f3wnanie grep() i grepl() w R: jaka jest r\u00f3\u017cnica?<\/title>\n<meta name=\"description\" content=\"Proste wyja\u015bnienie r\u00f3\u017cnicy pomi\u0119dzy funkcjami grep() i grepl() w R.\" \/>\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\/pl\/grep-kontra-grepl-r\/\" \/>\n<meta property=\"og:locale\" content=\"pl_PL\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Por\u00f3wnanie grep() i grepl() w R: jaka jest r\u00f3\u017cnica?\" \/>\n<meta property=\"og:description\" content=\"Proste wyja\u015bnienie r\u00f3\u017cnicy pomi\u0119dzy funkcjami grep() i grepl() w R.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/pl\/grep-kontra-grepl-r\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-28T04:57:15+00:00\" \/>\n<meta name=\"author\" content=\"Benjamin Anderson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Napisane przez\" \/>\n\t<meta name=\"twitter:data1\" content=\"Benjamin Anderson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Szacowany czas czytania\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minuty\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/pl\/grep-kontra-grepl-r\/\",\"url\":\"https:\/\/statorials.org\/pl\/grep-kontra-grepl-r\/\",\"name\":\"Por\u00f3wnanie grep() i grepl() w R: jaka jest r\u00f3\u017cnica?\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/pl\/#website\"},\"datePublished\":\"2023-07-28T04:57:15+00:00\",\"dateModified\":\"2023-07-28T04:57:15+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/pl\/#\/schema\/person\/6484727a4612df3e69f016c3129c6965\"},\"description\":\"Proste wyja\u015bnienie r\u00f3\u017cnicy pomi\u0119dzy funkcjami grep() i grepl() w R.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/pl\/grep-kontra-grepl-r\/#breadcrumb\"},\"inLanguage\":\"pl-PL\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/pl\/grep-kontra-grepl-r\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/pl\/grep-kontra-grepl-r\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Dom\",\"item\":\"https:\/\/statorials.org\/pl\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Por\u00f3wnanie grep() i grepl() w r: jaka jest r\u00f3\u017cnica?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/statorials.org\/pl\/#website\",\"url\":\"https:\/\/statorials.org\/pl\/\",\"name\":\"Statorials\",\"description\":\"Tw\u00f3j przewodnik po kompetencjach statystycznych!\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/statorials.org\/pl\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"pl-PL\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/statorials.org\/pl\/#\/schema\/person\/6484727a4612df3e69f016c3129c6965\",\"name\":\"Benjamin Anderson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"pl-PL\",\"@id\":\"https:\/\/statorials.org\/pl\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/statorials.org\/pl\/wp-content\/uploads\/2023\/11\/Benjamin-Anderson-96x96.jpg\",\"contentUrl\":\"https:\/\/statorials.org\/pl\/wp-content\/uploads\/2023\/11\/Benjamin-Anderson-96x96.jpg\",\"caption\":\"Benjamin Anderson\"},\"description\":\"Cze\u015b\u0107, jestem Benjamin i jestem emerytowanym profesorem statystyki, kt\u00f3ry zosta\u0142 oddanym nauczycielem Statorials. Dzi\u0119ki bogatemu do\u015bwiadczeniu i wiedzy specjalistycznej w dziedzinie statystyki ch\u0119tnie dziel\u0119 si\u0119 swoj\u0105 wiedz\u0105, aby wzmocni\u0107 pozycj\u0119 uczni\u00f3w za po\u015brednictwem Statorials. Wiedzie\u0107 wi\u0119cej\",\"sameAs\":[\"https:\/\/statorials.org\/pl\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Por\u00f3wnanie grep() i grepl() w R: jaka jest r\u00f3\u017cnica?","description":"Proste wyja\u015bnienie r\u00f3\u017cnicy pomi\u0119dzy funkcjami grep() i grepl() w R.","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\/pl\/grep-kontra-grepl-r\/","og_locale":"pl_PL","og_type":"article","og_title":"Por\u00f3wnanie grep() i grepl() w R: jaka jest r\u00f3\u017cnica?","og_description":"Proste wyja\u015bnienie r\u00f3\u017cnicy pomi\u0119dzy funkcjami grep() i grepl() w R.","og_url":"https:\/\/statorials.org\/pl\/grep-kontra-grepl-r\/","og_site_name":"Statorials","article_published_time":"2023-07-28T04:57:15+00:00","author":"Benjamin Anderson","twitter_card":"summary_large_image","twitter_misc":{"Napisane przez":"Benjamin Anderson","Szacowany czas czytania":"2 minuty"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/pl\/grep-kontra-grepl-r\/","url":"https:\/\/statorials.org\/pl\/grep-kontra-grepl-r\/","name":"Por\u00f3wnanie grep() i grepl() w R: jaka jest r\u00f3\u017cnica?","isPartOf":{"@id":"https:\/\/statorials.org\/pl\/#website"},"datePublished":"2023-07-28T04:57:15+00:00","dateModified":"2023-07-28T04:57:15+00:00","author":{"@id":"https:\/\/statorials.org\/pl\/#\/schema\/person\/6484727a4612df3e69f016c3129c6965"},"description":"Proste wyja\u015bnienie r\u00f3\u017cnicy pomi\u0119dzy funkcjami grep() i grepl() w R.","breadcrumb":{"@id":"https:\/\/statorials.org\/pl\/grep-kontra-grepl-r\/#breadcrumb"},"inLanguage":"pl-PL","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/pl\/grep-kontra-grepl-r\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/pl\/grep-kontra-grepl-r\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Dom","item":"https:\/\/statorials.org\/pl\/"},{"@type":"ListItem","position":2,"name":"Por\u00f3wnanie grep() i grepl() w r: jaka jest r\u00f3\u017cnica?"}]},{"@type":"WebSite","@id":"https:\/\/statorials.org\/pl\/#website","url":"https:\/\/statorials.org\/pl\/","name":"Statorials","description":"Tw\u00f3j przewodnik po kompetencjach statystycznych!","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/statorials.org\/pl\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"pl-PL"},{"@type":"Person","@id":"https:\/\/statorials.org\/pl\/#\/schema\/person\/6484727a4612df3e69f016c3129c6965","name":"Benjamin Anderson","image":{"@type":"ImageObject","inLanguage":"pl-PL","@id":"https:\/\/statorials.org\/pl\/#\/schema\/person\/image\/","url":"https:\/\/statorials.org\/pl\/wp-content\/uploads\/2023\/11\/Benjamin-Anderson-96x96.jpg","contentUrl":"https:\/\/statorials.org\/pl\/wp-content\/uploads\/2023\/11\/Benjamin-Anderson-96x96.jpg","caption":"Benjamin Anderson"},"description":"Cze\u015b\u0107, jestem Benjamin i jestem emerytowanym profesorem statystyki, kt\u00f3ry zosta\u0142 oddanym nauczycielem Statorials. Dzi\u0119ki bogatemu do\u015bwiadczeniu i wiedzy specjalistycznej w dziedzinie statystyki ch\u0119tnie dziel\u0119 si\u0119 swoj\u0105 wiedz\u0105, aby wzmocni\u0107 pozycj\u0119 uczni\u00f3w za po\u015brednictwem Statorials. Wiedzie\u0107 wi\u0119cej","sameAs":["https:\/\/statorials.org\/pl"]}]}},"yoast_meta":{"yoast_wpseo_title":"","yoast_wpseo_metadesc":"","yoast_wpseo_canonical":""},"_links":{"self":[{"href":"https:\/\/statorials.org\/pl\/wp-json\/wp\/v2\/posts\/953","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/statorials.org\/pl\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/statorials.org\/pl\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/statorials.org\/pl\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/statorials.org\/pl\/wp-json\/wp\/v2\/comments?post=953"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/pl\/wp-json\/wp\/v2\/posts\/953\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/pl\/wp-json\/wp\/v2\/media?parent=953"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/pl\/wp-json\/wp\/v2\/categories?post=953"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/pl\/wp-json\/wp\/v2\/tags?post=953"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}