{"id":1790,"date":"2023-07-24T23:38:42","date_gmt":"2023-07-24T23:38:42","guid":{"rendered":"https:\/\/statorials.org\/nl\/str_split-in-r\/"},"modified":"2023-07-24T23:38:42","modified_gmt":"2023-07-24T23:38:42","slug":"str_split-in-r","status":"publish","type":"post","link":"https:\/\/statorials.org\/nl\/str_split-in-r\/","title":{"rendered":"Hoe str_split in r te gebruiken (met voorbeelden)"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">De functie <strong>str_split()<\/strong> van het <a href=\"https:\/\/stringr.tidyverse.org\/\" target=\"_blank\" rel=\"noopener\">stringr-<\/a> pakket in R kan worden gebruikt om een string in meerdere stukken te splitsen. Deze functie gebruikt de volgende syntaxis:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>str_split(tekenreeks, patroon)<\/strong><\/span><\/p>\n<p> <span style=\"color: #000000;\">Goud:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\"><strong>tekenreeks:<\/strong> karaktervector<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>patroon:<\/strong> patroon waarop moet worden verdeeld<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">Op dezelfde manier kan de functie <strong>str_split_fixed()<\/strong> uit het stringr-pakket worden gebruikt om een string in een vast aantal stukken te splitsen. Deze functie gebruikt de volgende syntaxis:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>str_split_fixed(tekenreeks, patroon, n)<\/strong><\/span><\/p>\n<p> <span style=\"color: #000000;\">Goud:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\"><strong>tekenreeks:<\/strong> karaktervector<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>patroon:<\/strong> patroon waarop moet worden verdeeld<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>n:<\/strong> Aantal te retourneren stuks<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">Deze zelfstudie biedt voorbeelden van het gebruik van elk van deze functies op het volgende dataframe:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#create data frame<\/span>\ndf &lt;- data. <span style=\"color: #3366ff;\">frame<\/span> (team=c('andy &amp; bob', 'carl &amp; doug', 'eric &amp; frank'),\n                 dots=c(14, 17, 19))\n\n<span style=\"color: #008080;\">#view data frame\n<\/span>df\n\n          team points\n1 andy &amp; bob 14\n2 carl &amp; doug 17\n3 eric &amp; frank 19\n<\/strong><\/pre>\n<h3> <strong><span style=\"color: #000000;\">Voorbeeld 1: een tekenreeks splitsen met str_split()<\/span><\/strong><\/h3>\n<p> <span style=\"color: #000000;\">De volgende code laat zien hoe u de tekenreeks in de kolom &#8222;team&#8220; kunt splitsen met behulp van de functie <strong>str_split()<\/strong> :<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #993300;\">library<\/span> (stringr)<\/span>\n\n<\/span><span style=\"color: #008080;\">#split the string in the <em>team<\/em> column on \" &amp; \"\n<\/span>str_split(df$team, \" &amp; \")\n\n[[1]]\n[1] \u201candy\u201d \u201cbob\u201d \n\n[[2]]\n[1] \u201ccarl\u201d \u201cdoug\u201d\n\n[[3]]\n[1] \u201ceric\u201d \u201cfrank\u201d<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Het resultaat is een lijst met drie items die de namen van individuele spelers in elk team tonen.<\/span><\/p>\n<h3> <strong><span style=\"color: #000000;\">Voorbeeld 2:<\/span><\/strong> <strong><span style=\"color: #000000;\">een tekenreeks splitsen met str_split_fixed()<\/span><\/strong><\/h3>\n<p> <span style=\"color: #000000;\">De volgende code laat zien hoe u de tekenreeks in de kolom &#8222;team&#8220; in twee vaste stukken kunt splitsen met behulp van de functie <strong>str_split_fixed()<\/strong> :<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #993300;\">library<\/span> (stringr)\n\n<span style=\"color: #008080;\">#split the string in the <em>team<\/em> column on \" &amp; \"<\/span>\nstr_split_fixed(df$team, \" &amp; \", 2)\n\n     [,1] [,2]   \n[1,] \u201candy\u201d \u201cbob\u201d  \n[2,] \"carl\" \"doug\" \n[3,] \"eric\" \"frank\"<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Het resultaat is een matrix met twee kolommen en drie rijen.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Een nuttige toepassing van de functie <strong>str_split_fixed()<\/strong> is om de resulterende matrix aan het einde van het dataframe toe te voegen. Bijvoorbeeld:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #993300;\">library<\/span> (stringr)\n\n<span style=\"color: #008080;\">#split the string in the <em>team<\/em> column and append resulting matrix to data frame\n<\/span>df[, 3:4] &lt;- str_split_fixed(df$team, \" &amp; \", 2)\n\n<span style=\"color: #008080;\">#view data frame<\/span>\ndf\n          team points V3 V4\n1 andy &amp; bob 14 andy bob\n2 carl &amp; doug 17 carl doug\n3 eric &amp; frank 19 eric frank<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">De kolom met het label \u201cV3\u201d toont de naam van de speler van het eerste team en de kolom met het label \u201cV4\u201d toont de naam van de speler van het tweede team.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Aanvullende bronnen<\/strong><\/span><\/h3>\n<p> <a href=\"https:\/\/statorials.org\/nl\/str_replace-in-r\/\" target=\"_blank\" rel=\"noopener\">Hoe str_replace te gebruiken in R<\/a><br \/> Hoe gedeeltelijke stringmatching uit te voeren in R<br \/> <a href=\"https:\/\/statorials.org\/nl\/converteer-tekenreeksen-naar-datums-in-r\/\" target=\"_blank\" rel=\"noopener\">Hoe tekenreeksen naar datums in R te converteren<\/a><br \/> <a href=\"https:\/\/statorials.org\/nl\/numeriek-teken-in-r\/\" target=\"_blank\" rel=\"noopener\">Hoe teken naar numeriek te converteren in R<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>De functie str_split() van het stringr- pakket in R kan worden gebruikt om een string in meerdere stukken te splitsen. Deze functie gebruikt de volgende syntaxis: str_split(tekenreeks, patroon) Goud: tekenreeks: karaktervector patroon: patroon waarop moet worden verdeeld Op dezelfde manier kan de functie str_split_fixed() uit het stringr-pakket worden gebruikt om een string in een vast [&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-1790","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>Hoe str_split in R te gebruiken (met voorbeelden) \u2013 Statorials<\/title>\n<meta name=\"description\" content=\"In deze tutorial wordt uitgelegd hoe je de str_split-functie in R gebruikt, met verschillende voorbeelden.\" \/>\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\/str_split-in-r\/\" \/>\n<meta property=\"og:locale\" content=\"de_DE\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Hoe str_split in R te gebruiken (met voorbeelden) \u2013 Statorials\" \/>\n<meta property=\"og:description\" content=\"In deze tutorial wordt uitgelegd hoe je de str_split-functie in R gebruikt, met verschillende voorbeelden.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/nl\/str_split-in-r\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-24T23:38:42+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\/str_split-in-r\/\",\"url\":\"https:\/\/statorials.org\/nl\/str_split-in-r\/\",\"name\":\"Hoe str_split in R te gebruiken (met voorbeelden) \u2013 Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/nl\/#website\"},\"datePublished\":\"2023-07-24T23:38:42+00:00\",\"dateModified\":\"2023-07-24T23:38:42+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219\"},\"description\":\"In deze tutorial wordt uitgelegd hoe je de str_split-functie in R gebruikt, met verschillende voorbeelden.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/nl\/str_split-in-r\/#breadcrumb\"},\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/nl\/str_split-in-r\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/nl\/str_split-in-r\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Thuis\",\"item\":\"https:\/\/statorials.org\/nl\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Hoe str_split in r te gebruiken (met voorbeelden)\"}]},{\"@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":"Hoe str_split in R te gebruiken (met voorbeelden) \u2013 Statorials","description":"In deze tutorial wordt uitgelegd hoe je de str_split-functie in R gebruikt, met verschillende voorbeelden.","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\/str_split-in-r\/","og_locale":"de_DE","og_type":"article","og_title":"Hoe str_split in R te gebruiken (met voorbeelden) \u2013 Statorials","og_description":"In deze tutorial wordt uitgelegd hoe je de str_split-functie in R gebruikt, met verschillende voorbeelden.","og_url":"https:\/\/statorials.org\/nl\/str_split-in-r\/","og_site_name":"Statorials","article_published_time":"2023-07-24T23:38:42+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\/str_split-in-r\/","url":"https:\/\/statorials.org\/nl\/str_split-in-r\/","name":"Hoe str_split in R te gebruiken (met voorbeelden) \u2013 Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/nl\/#website"},"datePublished":"2023-07-24T23:38:42+00:00","dateModified":"2023-07-24T23:38:42+00:00","author":{"@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219"},"description":"In deze tutorial wordt uitgelegd hoe je de str_split-functie in R gebruikt, met verschillende voorbeelden.","breadcrumb":{"@id":"https:\/\/statorials.org\/nl\/str_split-in-r\/#breadcrumb"},"inLanguage":"de","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/nl\/str_split-in-r\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/nl\/str_split-in-r\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Thuis","item":"https:\/\/statorials.org\/nl\/"},{"@type":"ListItem","position":2,"name":"Hoe str_split in r te gebruiken (met voorbeelden)"}]},{"@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\/1790","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=1790"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts\/1790\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/media?parent=1790"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/categories?post=1790"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/tags?post=1790"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}