{"id":3796,"date":"2023-07-15T12:24:30","date_gmt":"2023-07-15T12:24:30","guid":{"rendered":"https:\/\/statorials.org\/nl\/dplyr-mutatiefactor\/"},"modified":"2023-07-15T12:24:30","modified_gmt":"2023-07-15T12:24:30","slug":"dplyr-mutatiefactor","status":"publish","type":"post","link":"https:\/\/statorials.org\/nl\/dplyr-mutatiefactor\/","title":{"rendered":"Dplyr: hoe factorniveaus te veranderen met mute()"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">U kunt de volgende basissyntaxis in <a href=\"https:\/\/dplyr.tidyverse.org\/\" target=\"_blank\" rel=\"noopener\">dplyr<\/a> gebruiken om de niveaus van een factorvariabele te wijzigen met behulp van de functie <strong>mute()<\/strong> :<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\">library<\/span> (dplyr)\n\ndf &lt;- df %&gt;% mutate(team=recode(team,\n                                ' <span style=\"color: #ff0000;\">H<\/span> ' = ' <span style=\"color: #ff0000;\">Hawks<\/span> ',\n                                ' <span style=\"color: #ff0000;\">M<\/span> ' = ' <span style=\"color: #ff0000;\">Mavs<\/span> ',\n                                ' <span style=\"color: #ff0000;\">C<\/span> ' = ' <span style=\"color: #ff0000;\">Cavs<\/span> '))\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Deze specifieke syntaxis brengt de volgende wijzigingen aan in de <strong>teamvariabele<\/strong> in het dataframe:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\">&#8218;H&#8216; wordt &#8218;Hawks&#8216;<\/span><\/li>\n<li> <span style=\"color: #000000;\">&#8218;M&#8216; wordt &#8218;Mavs&#8216;<\/span><\/li>\n<li> <span style=\"color: #000000;\">&#8218;C&#8216; wordt &#8218;Cavs&#8216;<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">Het volgende voorbeeld laat zien hoe u deze syntaxis in de praktijk kunt gebruiken.<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Voorbeeld: factorniveaus wijzigen met mute()<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Stel dat we het volgende dataframe in R hebben dat informatie bevat over verschillende basketbalspelers:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#create data frame\n<\/span>df &lt;- data. <span style=\"color: #3366ff;\">frame<\/span> (team=factor(c('H', 'H', 'M', 'M', 'C', 'C')),\n                 dots=c(22, 35, 19, 15, 29, 23))\n\n<span style=\"color: #008080;\">#view data frame\n<\/span>df\n\n  team points\n1:22 a.m.\n2:35 a.m.\n3 M 19\n4 M 15\n5 C 29\n6 C 23\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">We kunnen de volgende syntaxis gebruiken met de functie <strong>mute()<\/strong> van het <strong>dplyr-<\/strong> pakket om de niveaus van de <strong>teamvariabele<\/strong> te wijzigen:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\">library<\/span> (dplyr)\n\n<span style=\"color: #008080;\">#change factor levels of team variable\n<\/span>df &lt;- df %&gt;% mutate(team=recode(team,\n                                ' <span style=\"color: #ff0000;\">H<\/span> ' = ' <span style=\"color: #ff0000;\">Hawks<\/span> ',\n                                ' <span style=\"color: #ff0000;\">M<\/span> ' = ' <span style=\"color: #ff0000;\">Mavs<\/span> ',\n                                ' <span style=\"color: #ff0000;\">C<\/span> ' = ' <span style=\"color: #ff0000;\">Cavs<\/span> '))\n\n<span style=\"color: #008080;\">#view updated data frame<\/span>\ndf\n\n   team points\n1 Hawks 22\n2 Hawks 35\n3 Mavs 19\n4 Mavs 15\n5 Cavs 29\n6 Cavs 23\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Met behulp van deze syntaxis konden we de<\/span> <span style=\"color: #000000;\">volgende wijzigingen aanbrengen in de <strong>teamvariabele<\/strong> in het dataframe:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\">&#8218;H&#8216; wordt &#8218;Hawks&#8216;<\/span><\/li>\n<li> <span style=\"color: #000000;\">&#8218;M&#8216; wordt &#8218;Mavs&#8216;<\/span><\/li>\n<li> <span style=\"color: #000000;\">&#8218;C&#8216; wordt &#8218;Cavs&#8216;<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">We kunnen verifi\u00ebren dat de factorniveaus zijn gewijzigd met behulp van de functie niveaus <strong>()<\/strong> :<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#display factor levels of team variable\n<\/span>levels(df$team)\n\n[1] \u201cCavs\u201d \u201cHawks\u201d \u201cMavs\u201d \n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Houd er ook rekening mee dat u ervoor kunt kiezen om slechts \u00e9\u00e9n factorniveau te wijzigen in plaats van allemaal.<\/span><\/p>\n<p> <span style=\"color: #000000;\">We kunnen bijvoorbeeld de volgende syntaxis gebruiken om alleen &#8222;H&#8220; te vervangen door &#8222;Hawks&#8220; en de andere factorniveaus ongewijzigd te laten:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\">library<\/span> (dplyr)\n\n<span style=\"color: #008080;\">#change one factor level of team variable\n<\/span>df &lt;- df %&gt;% mutate(team=recode(team, ' <span style=\"color: #ff0000;\">H<\/span> ' = ' <span style=\"color: #ff0000;\">Hawks<\/span> '))\n\n<span style=\"color: #008080;\">#view updated data frame<\/span>\ndf\n\n   team points\n1 Hawks 22\n2 Hawks 35\n3 M 19\n4 M 15\n5 C 29\n6 C 23\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Merk op dat &#8222;H&#8220; werd vervangen door &#8222;Hawks&#8220;, maar dat de andere twee factorniveaus ongewijzigd bleven.<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Aanvullende bronnen<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">In de volgende tutorials wordt uitgelegd hoe u andere veelvoorkomende taken in dplyr uitvoert:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/nl\/dplyr-regels-verwijderen\/\" target=\"_blank\" rel=\"noopener\">Rijen verwijderen met dplyr<\/a><br \/> <a href=\"https:\/\/statorials.org\/nl\/dplyr-selecteer-kolommen-op-index\/\" target=\"_blank\" rel=\"noopener\">Kolommen selecteren op index met behulp van dplyr<\/a><br \/> <a href=\"https:\/\/statorials.org\/nl\/filter-regels-die-dplyr-tekenreeks-bevatten\/\" target=\"_blank\" rel=\"noopener\">Hoe u rijen kunt filteren die een bepaalde tekenreeks bevatten met behulp van dplyr<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>U kunt de volgende basissyntaxis in dplyr gebruiken om de niveaus van een factorvariabele te wijzigen met behulp van de functie mute() : library (dplyr) df &lt;- df %&gt;% mutate(team=recode(team, &#8218; H &#8218; = &#8218; Hawks &#8218;, &#8218; M &#8218; = &#8218; Mavs &#8218;, &#8218; C &#8218; = &#8218; Cavs &#8218;)) Deze specifieke syntaxis brengt [&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-3796","post","type-post","status-publish","format-standard","hentry","category-gids"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>dplyr: Hoe factorniveaus te veranderen met mute() - Statorials<\/title>\n<meta name=\"description\" content=\"In deze tutorial wordt uitgelegd hoe u de functie mute() in dplyr met factoren gebruikt, inclusief een voorbeeld.\" \/>\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\/nl\/dplyr-mutatiefactor\/\" \/>\n<meta property=\"og:locale\" content=\"de_DE\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"dplyr: Hoe factorniveaus te veranderen met mute() - Statorials\" \/>\n<meta property=\"og:description\" content=\"In deze tutorial wordt uitgelegd hoe u de functie mute() in dplyr met factoren gebruikt, inclusief een voorbeeld.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/nl\/dplyr-mutatiefactor\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-15T12:24:30+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=\"2\u00a0Minuten\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/nl\/dplyr-mutatiefactor\/\",\"url\":\"https:\/\/statorials.org\/nl\/dplyr-mutatiefactor\/\",\"name\":\"dplyr: Hoe factorniveaus te veranderen met mute() - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/nl\/#website\"},\"datePublished\":\"2023-07-15T12:24:30+00:00\",\"dateModified\":\"2023-07-15T12:24:30+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219\"},\"description\":\"In deze tutorial wordt uitgelegd hoe u de functie mute() in dplyr met factoren gebruikt, inclusief een voorbeeld.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/nl\/dplyr-mutatiefactor\/#breadcrumb\"},\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/nl\/dplyr-mutatiefactor\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/nl\/dplyr-mutatiefactor\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Thuis\",\"item\":\"https:\/\/statorials.org\/nl\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Dplyr: hoe factorniveaus te veranderen met mute()\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/statorials.org\/nl\/#website\",\"url\":\"https:\/\/statorials.org\/nl\/\",\"name\":\"Statorials\",\"description\":\"Uw gids voor statistische competentie\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/statorials.org\/nl\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"de\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219\",\"name\":\"Dr.benjamin anderson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"de\",\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/statorials.org\/nl\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"contentUrl\":\"http:\/\/statorials.org\/nl\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"caption\":\"Dr.benjamin anderson\"},\"description\":\"Ik ben Benjamin, een gepensioneerde hoogleraar statistiek die nu een toegewijde Statorials-lesgever is. Ik heb uitgebreide ervaring en expertise op het gebied van statistiek en ik ben vastbesloten om mijn kennis te delen met studenten via Statorials. Lees verder\",\"sameAs\":[\"http:\/\/statorials.org\/nl\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"dplyr: Hoe factorniveaus te veranderen met mute() - Statorials","description":"In deze tutorial wordt uitgelegd hoe u de functie mute() in dplyr met factoren gebruikt, inclusief een voorbeeld.","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\/nl\/dplyr-mutatiefactor\/","og_locale":"de_DE","og_type":"article","og_title":"dplyr: Hoe factorniveaus te veranderen met mute() - Statorials","og_description":"In deze tutorial wordt uitgelegd hoe u de functie mute() in dplyr met factoren gebruikt, inclusief een voorbeeld.","og_url":"https:\/\/statorials.org\/nl\/dplyr-mutatiefactor\/","og_site_name":"Statorials","article_published_time":"2023-07-15T12:24:30+00:00","author":"Dr.benjamin anderson","twitter_card":"summary_large_image","twitter_misc":{"Verfasst von":"Dr.benjamin anderson","Gesch\u00e4tzte Lesezeit":"2\u00a0Minuten"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/nl\/dplyr-mutatiefactor\/","url":"https:\/\/statorials.org\/nl\/dplyr-mutatiefactor\/","name":"dplyr: Hoe factorniveaus te veranderen met mute() - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/nl\/#website"},"datePublished":"2023-07-15T12:24:30+00:00","dateModified":"2023-07-15T12:24:30+00:00","author":{"@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219"},"description":"In deze tutorial wordt uitgelegd hoe u de functie mute() in dplyr met factoren gebruikt, inclusief een voorbeeld.","breadcrumb":{"@id":"https:\/\/statorials.org\/nl\/dplyr-mutatiefactor\/#breadcrumb"},"inLanguage":"de","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/nl\/dplyr-mutatiefactor\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/nl\/dplyr-mutatiefactor\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Thuis","item":"https:\/\/statorials.org\/nl\/"},{"@type":"ListItem","position":2,"name":"Dplyr: hoe factorniveaus te veranderen met mute()"}]},{"@type":"WebSite","@id":"https:\/\/statorials.org\/nl\/#website","url":"https:\/\/statorials.org\/nl\/","name":"Statorials","description":"Uw gids voor statistische competentie","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/statorials.org\/nl\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"de"},{"@type":"Person","@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219","name":"Dr.benjamin anderson","image":{"@type":"ImageObject","inLanguage":"de","@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/image\/","url":"http:\/\/statorials.org\/nl\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","contentUrl":"http:\/\/statorials.org\/nl\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","caption":"Dr.benjamin anderson"},"description":"Ik ben Benjamin, een gepensioneerde hoogleraar statistiek die nu een toegewijde Statorials-lesgever is. Ik heb uitgebreide ervaring en expertise op het gebied van statistiek en ik ben vastbesloten om mijn kennis te delen met studenten via Statorials. Lees verder","sameAs":["http:\/\/statorials.org\/nl"]}]}},"yoast_meta":{"yoast_wpseo_title":"","yoast_wpseo_metadesc":"","yoast_wpseo_canonical":""},"_links":{"self":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts\/3796","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/comments?post=3796"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts\/3796\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/media?parent=3796"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/categories?post=3796"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/tags?post=3796"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}