{"id":942,"date":"2023-07-28T05:49:15","date_gmt":"2023-07-28T05:49:15","guid":{"rendered":"https:\/\/statorials.org\/de\/filterzeilen-r\/"},"modified":"2023-07-28T05:49:15","modified_gmt":"2023-07-28T05:49:15","slug":"filterzeilen-r","status":"publish","type":"post","link":"https:\/\/statorials.org\/de\/filterzeilen-r\/","title":{"rendered":"So filtern sie zeilen in r"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Oft sind Sie an einer Teilmenge eines Datenrahmens interessiert, die auf bestimmten Bedingungen in R basiert. Gl\u00fccklicherweise ist dies mit der Funktion <a href=\"https:\/\/dplyr.tidyverse.org\/reference\/filter.html\" target=\"_blank\" rel=\"noopener noreferrer\">filter()<\/a> aus dem <a href=\"https:\/\/dplyr.tidyverse.org\/index.html\" target=\"_blank\" rel=\"noopener noreferrer\">dplyr-<\/a> Paket einfach zu bewerkstelligen.<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>library(dplyr)<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">In diesem Tutorial werden mehrere Beispiele f\u00fcr die praktische Verwendung dieser Funktion mithilfe des integrierten dplyr-Datensatzes namens <strong>starwars<\/strong> erl\u00e4utert:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#view first six rows of starwars dataset<\/span>\nhead(starwars)\n\n# A tibble: 6 x 13\n  name height mass hair_color skin_color eye_color birth_year gender homeworld\n                                   \n1 Luke~ 172 77 blond fair blue 19 male Tatooine \n2 C-3PO 167 75 &lt;NA&gt; gold yellow 112 &lt;NA&gt; Tatooine \n3 R2-D2 96 32 &lt;NA&gt; white, bl~ red 33 &lt;NA&gt; Naboo    \n4 Dart~ 202 136 none white yellow 41.9 male Tatooine \n5 Leia~ 150 49 brown light brown 19 female Alderaan \n6 Owen~ 178 120 brown, gr~ light blue 52 male Tatooine \n# ... with 4 more variables: species , films , vehicles ,\n# starships \n<\/strong><\/pre>\n<h3> <strong><span style=\"color: #000000;\">Beispiel 1: Zeilen filtern, die einem bestimmten Wert entsprechen<\/span><\/strong><\/h3>\n<p> <span style=\"color: #000000;\">Der folgende Code zeigt, wie der Datensatz nach Zeilen gefiltert wird, in denen die Variable \u201especies\u201c gleich Droid ist.<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>starwars %&gt;% filter(species == ' <span style=\"color: #008000;\">Droid<\/span> ')\n\n# A tibble: 5 x 13\n  name height mass hair_color skin_color eye_color birth_year gender homeworld\n                                   \n1 C-3PO 167 75 gold yellow 112 Tatooine \n2 R2-D2 96 32 white, bl~ red 33 Naboo    \n3 R5-D4 97 32 white, red red NA Tatooine \n4 IG-88 200 140 none metal red 15 none        \n5 BB8 NA NA none none black NA none        \n# ... with 4 more variables: species , films , vehicles ,\n# starships \n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Wir k\u00f6nnen sehen, dass 5 Zeilen des Datensatzes diese Bedingung erf\u00fcllen, wie durch <em>#A tibble: 5 x 13<\/em> angezeigt.<\/span><\/p>\n<h3> <strong><span style=\"color: #000000;\">Beispiel 2: Zeilen mit \u201eUnd\u201c filtern<\/span><\/strong><\/h3>\n<p> <span style=\"color: #000000;\">Wir k\u00f6nnen auch Zeilen filtern, in denen die Spezies Droide ist <strong>und<\/strong> die Augenfarbe rot ist:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>starwars %&gt;% filter(species == ' <span style=\"color: #008000;\">Droid<\/span> ' <span style=\"color: #993300;\">&amp;<\/span> eye_color == ' <span style=\"color: #008000;\">red<\/span> ')\n\n# A tibble: 3 x 13\n  name height mass hair_color skin_color eye_color birth_year gender homeworld\n                                   \n1 R2-D2 96 32 &lt;NA&gt; white, bl~ red 33 &lt;NA&gt; Naboo    \n2 R5-D4 97 32 &lt;NA&gt; white, red red NA &lt;NA&gt; Tatooine \n3 IG-88 200 140 none metal red 15 none &lt;NA&gt;      \n# ... with 4 more variables: species , films , vehicles ,\n# starships \n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Wir k\u00f6nnen sehen, dass 3 Zeilen im Datensatz diese Bedingung erf\u00fcllen.<\/span><\/p>\n<h3> <strong><span style=\"color: #000000;\">Beispiel 3: Zeilen mit \u201eOder\u201c filtern<\/span><\/strong><\/h3>\n<p> <span style=\"color: #000000;\">Wir k\u00f6nnen auch Zeilen filtern, in denen die Spezies Droide ist <strong>oder<\/strong> die Augenfarbe rot ist:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>starwars %&gt;% filter(species == ' <span style=\"color: #008000;\">Droid<\/span> ' <span style=\"color: #993300;\">|<\/span> eye_color == ' <span style=\"color: #008000;\">red<\/span> ')\n\n# A tibble: 7 x 13\n  name height mass hair_color skin_color eye_color birth_year gender homeworld\n                                   \n1 C-3PO 167 75 &lt;NA&gt; gold yellow 112 &lt;NA&gt; Tatooine \n2 R2-D2 96 32 &lt;NA&gt; white, bl~ red 33 &lt;NA&gt; Naboo    \n3 R5-D4 97 32 &lt;NA&gt; white, red red NA &lt;NA&gt; Tatooine \n4 IG-88 200 140 none metal red 15 none &lt;NA&gt;     \n5 Bossk 190 113 none green red 53 male Trandosha\n6 Nute~ 191 90 none mottled g~ red NA male Cato Nei~\n7 BB8 NA NA none none black NA none &lt;NA&gt;     \n# ... with 4 more variables: species , films , vehicles ,\n# starships  \n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Wir k\u00f6nnen sehen, dass 7 Zeilen im Datensatz diese Bedingung erf\u00fcllen.<\/span><\/p>\n<h3> <strong><span style=\"color: #000000;\">Beispiel 4: Zeilen mit Werten in einer Liste filtern<\/span><\/strong><\/h3>\n<p> <span style=\"color: #000000;\">Wir k\u00f6nnen auch Zeilen filtern, in denen die Augenfarbe in einer Farbliste erscheint:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>starwars %&gt;% filter(eye_color <span style=\"color: #993300;\">%in%<\/span> c(' <span style=\"color: #008000;\">blue<\/span> ', ' <span style=\"color: #008000;\">yellow<\/span> ', ' <span style=\"color: #008000;\">red<\/span> '))\n\n# A tibble: 35 x 13\n   name height mass hair_color skin_color eye_color birth_year gender\n                               \n 1 Luke~ 172 77 blond fair blue 19 male  \n 2 C-3PO 167 75 &lt;NA&gt; gold yellow 112 &lt;NA&gt; \n 3 R2-D2 96 32 &lt;NA&gt; white, bl~ red 33 &lt;NA&gt;  \n 4 Dart~ 202 136 none white yellow 41.9 male  \n 5 Owen~ 178 120 brown, gr~ light blue 52 male  \n 6 Beru~ 165 75 brown light blue 47 female\n 7 R5-D4 97 32 &lt;NA&gt; white, red red NA &lt;NA&gt; \n 8 Anak~ 188 84 blond fair blue 41.9 male  \n 9 Wilh~ 180 NA auburn, g~ fair blue 64 male  \n10 Chew~ 228 112 brown unknown blue 200 male  \n# ... with 25 more rows, and 5 more variables: homeworld, species,\n# films, vehicles, starships  \n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Wir k\u00f6nnen sehen, dass 35 Zeilen im Datensatz eine blaue, gelbe oder rote Augenfarbe hatten.<\/span><\/p>\n<p> <strong><span style=\"color: #000000;\">Verwandte Themen:<\/span><\/strong> <a href=\"https:\/\/statorials.org\/de\/im-operator-in-r\/\" target=\"_blank\" rel=\"noopener noreferrer\">So verwenden Sie den %in%-Operator in R (mit Beispielen)<\/a><\/p>\n<h3> <strong><span style=\"color: #000000;\">Beispiel 5: Zeilen nach \u201ekleiner als\u201c oder \u201egr\u00f6\u00dfer als\u201c filtern<\/span><\/strong><\/h3>\n<p> <span style=\"color: #000000;\">Wir k\u00f6nnen Zeilen auch mithilfe von Kleiner-als- oder Gr\u00f6\u00dfer-als-Operationen f\u00fcr numerische Variablen filtern:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#find rows where height is greater than 250<\/span>\nstarwars %&gt;% filter(height <span style=\"color: #993300;\">&gt;<\/span> 250)\n\n# A tibble: 1 x 13\n  name height mass hair_color skin_color eye_color birth_year gender homeworld\n                                   \n1 Yara~ 264 NA none white yellow NA male Quermia  \n# ... with 4 more variables: species , films , vehicles ,\n# starships   \n\n<span style=\"color: #008080;\">#find rows where height is between 200 and 220<\/span>\nstarwars %&gt;% filter(height <span style=\"color: #993300;\">&gt;<\/span> 200 <span style=\"color: #993300;\">&amp;<\/span> height <span style=\"color: #993300;\">&lt;<\/span> 220)\n\n# A tibble: 5 x 13\n  name height mass hair_color skin_color eye_color birth_year gender homeworld\n                                   \n1 Dart~ 202 136 none white yellow 41.9 male Tatooine \n2 Rugo~ 206 NA none green orange NA male Naboo    \n3 Taun~ 213 NA none gray black NA female Kamino   \n4 Grie~ 216 159 none brown, wh~ green, y~ NA male Kalee    \n5 Tion~ 206 80 none gray black NA male Utapau   \n# ... with 4 more variables: species , films , vehicles ,\n# starships \n\n<span style=\"color: #008080;\">#find rows where height is above the average height\n<span style=\"color: #000000;\">starwars %&gt;% filter(height <span style=\"color: #993300;\">&gt;<\/span> <span style=\"color: #3366ff;\">mean<\/span> (height, na.rm = <span style=\"color: #008000;\">TRUE<\/span> ))\n\n# A tibble: 51 x 13\n   name height mass hair_color skin_color eye_color birth_year gender\n                               \n 1 Dart~ 202 136 none white yellow 41.9 male  \n 2 Owen~ 178 120 brown, gr~ light blue 52 male  \n 3 Bigg~ 183 84 black light brown 24 male  \n 4 Obi-~ 182 77 auburn, w~ fair blue-gray 57 male  \n 5 Anak~ 188 84 blond fair blue 41.9 male  \n 6 Wilh~ 180 NA auburn, g~ fair blue 64 male  \n 7 Chew~ 228 112 brown unknown blue 200 male  \n 8 Han ~ 180 80 brown fair brown 29 male  \n 9 Jabb~ 175 1358 &lt;NA&gt; green-tan~ orange 600 herma~\n10 Jek ~ 180 110 brown fair blue NA male  \n# ... with 41 more rows, and 5 more variables: homeworld, species,\n# films, vehicles, starships<\/span><\/span>\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\"><em>Die vollst\u00e4ndige Dokumentation zur Funktion <strong>filter()<\/strong> finden Sie <a href=\"https:\/\/dplyr.tidyverse.org\/reference\/filter.html\" target=\"_blank\" rel=\"noopener noreferrer\">hier<\/a> .<\/em><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Oft sind Sie an einer Teilmenge eines Datenrahmens interessiert, die auf bestimmten Bedingungen in R basiert. Gl\u00fccklicherweise ist dies mit der Funktion filter() aus dem dplyr- Paket einfach zu bewerkstelligen. library(dplyr) In diesem Tutorial werden mehrere Beispiele f\u00fcr die praktische Verwendung dieser Funktion mithilfe des integrierten dplyr-Datensatzes namens starwars erl\u00e4utert: #view first six rows of [&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>So filtern Sie Zeilen in R \u2013 Statorials<\/title>\n<meta name=\"description\" content=\"Eine einfache Erkl\u00e4rung zum Filtern von Daten in R mithilfe der Funktion filter() aus dem dplyr-Paket.\" \/>\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\/de\/filterzeilen-r\/\" \/>\n<meta property=\"og:locale\" content=\"de_DE\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"So filtern Sie Zeilen in R \u2013 Statorials\" \/>\n<meta property=\"og:description\" content=\"Eine einfache Erkl\u00e4rung zum Filtern von Daten in R mithilfe der Funktion filter() aus dem dplyr-Paket.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/de\/filterzeilen-r\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-28T05:49:15+00:00\" \/>\n<meta name=\"author\" content=\"Dr. Benjamin Anderson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Verfasst von\" \/>\n\t<meta name=\"twitter:data1\" content=\"Dr. Benjamin Anderson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Gesch\u00e4tzte Lesezeit\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 Minuten\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/de\/filterzeilen-r\/\",\"url\":\"https:\/\/statorials.org\/de\/filterzeilen-r\/\",\"name\":\"So filtern Sie Zeilen in R \u2013 Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/de\/#website\"},\"datePublished\":\"2023-07-28T05:49:15+00:00\",\"dateModified\":\"2023-07-28T05:49:15+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/de\/#\/schema\/person\/ec75c4d6365f2708f8a0ad3a42121aa0\"},\"description\":\"Eine einfache Erkl\u00e4rung zum Filtern von Daten in R mithilfe der Funktion filter() aus dem dplyr-Paket.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/de\/filterzeilen-r\/#breadcrumb\"},\"inLanguage\":\"de-DE\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/de\/filterzeilen-r\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/de\/filterzeilen-r\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Heim\",\"item\":\"https:\/\/statorials.org\/de\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"So filtern sie zeilen in r\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/statorials.org\/de\/#website\",\"url\":\"https:\/\/statorials.org\/de\/\",\"name\":\"Statorials\",\"description\":\"Ihr Leitfaden f\u00fcr statistische Kompetenz !\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/statorials.org\/de\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"de-DE\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/statorials.org\/de\/#\/schema\/person\/ec75c4d6365f2708f8a0ad3a42121aa0\",\"name\":\"Dr. Benjamin Anderson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"de-DE\",\"@id\":\"https:\/\/statorials.org\/de\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/statorials.org\/de\/wp-content\/uploads\/2023\/11\/Benjamin-Anderson-96x96.jpg\",\"contentUrl\":\"https:\/\/statorials.org\/de\/wp-content\/uploads\/2023\/11\/Benjamin-Anderson-96x96.jpg\",\"caption\":\"Dr. Benjamin Anderson\"},\"description\":\"Hallo, ich bin Benjamin, ein pensionierter Statistikprofessor, der sich zum engagierten Statorials-Lehrer entwickelt hat. Mit umfassender Erfahrung und Fachwissen auf dem Gebiet der Statistik bin ich bestrebt, mein Wissen zu teilen, um Studenten durch Statorials zu bef\u00e4higen. Mehr wissen\",\"sameAs\":[\"https:\/\/statorials.org\/de\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"So filtern Sie Zeilen in R \u2013 Statorials","description":"Eine einfache Erkl\u00e4rung zum Filtern von Daten in R mithilfe der Funktion filter() aus dem dplyr-Paket.","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\/de\/filterzeilen-r\/","og_locale":"de_DE","og_type":"article","og_title":"So filtern Sie Zeilen in R \u2013 Statorials","og_description":"Eine einfache Erkl\u00e4rung zum Filtern von Daten in R mithilfe der Funktion filter() aus dem dplyr-Paket.","og_url":"https:\/\/statorials.org\/de\/filterzeilen-r\/","og_site_name":"Statorials","article_published_time":"2023-07-28T05:49:15+00:00","author":"Dr. Benjamin Anderson","twitter_card":"summary_large_image","twitter_misc":{"Verfasst von":"Dr. Benjamin Anderson","Gesch\u00e4tzte Lesezeit":"5 Minuten"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/de\/filterzeilen-r\/","url":"https:\/\/statorials.org\/de\/filterzeilen-r\/","name":"So filtern Sie Zeilen in R \u2013 Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/de\/#website"},"datePublished":"2023-07-28T05:49:15+00:00","dateModified":"2023-07-28T05:49:15+00:00","author":{"@id":"https:\/\/statorials.org\/de\/#\/schema\/person\/ec75c4d6365f2708f8a0ad3a42121aa0"},"description":"Eine einfache Erkl\u00e4rung zum Filtern von Daten in R mithilfe der Funktion filter() aus dem dplyr-Paket.","breadcrumb":{"@id":"https:\/\/statorials.org\/de\/filterzeilen-r\/#breadcrumb"},"inLanguage":"de-DE","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/de\/filterzeilen-r\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/de\/filterzeilen-r\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Heim","item":"https:\/\/statorials.org\/de\/"},{"@type":"ListItem","position":2,"name":"So filtern sie zeilen in r"}]},{"@type":"WebSite","@id":"https:\/\/statorials.org\/de\/#website","url":"https:\/\/statorials.org\/de\/","name":"Statorials","description":"Ihr Leitfaden f\u00fcr statistische Kompetenz !","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/statorials.org\/de\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"de-DE"},{"@type":"Person","@id":"https:\/\/statorials.org\/de\/#\/schema\/person\/ec75c4d6365f2708f8a0ad3a42121aa0","name":"Dr. Benjamin Anderson","image":{"@type":"ImageObject","inLanguage":"de-DE","@id":"https:\/\/statorials.org\/de\/#\/schema\/person\/image\/","url":"https:\/\/statorials.org\/de\/wp-content\/uploads\/2023\/11\/Benjamin-Anderson-96x96.jpg","contentUrl":"https:\/\/statorials.org\/de\/wp-content\/uploads\/2023\/11\/Benjamin-Anderson-96x96.jpg","caption":"Dr. Benjamin Anderson"},"description":"Hallo, ich bin Benjamin, ein pensionierter Statistikprofessor, der sich zum engagierten Statorials-Lehrer entwickelt hat. Mit umfassender Erfahrung und Fachwissen auf dem Gebiet der Statistik bin ich bestrebt, mein Wissen zu teilen, um Studenten durch Statorials zu bef\u00e4higen. Mehr wissen","sameAs":["https:\/\/statorials.org\/de"]}]}},"yoast_meta":{"yoast_wpseo_title":"","yoast_wpseo_metadesc":"","yoast_wpseo_canonical":""},"_links":{"self":[{"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/posts\/942"}],"collection":[{"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/comments?post=942"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/posts\/942\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/media?parent=942"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/categories?post=942"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/tags?post=942"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}