{"id":2575,"date":"2023-07-21T16:20:29","date_gmt":"2023-07-21T16:20:29","guid":{"rendered":"https:\/\/statorials.org\/nl\/r-maak-een-categorische-variabele-van-continue\/"},"modified":"2023-07-21T16:20:29","modified_gmt":"2023-07-21T16:20:29","slug":"r-maak-een-categorische-variabele-van-continue","status":"publish","type":"post","link":"https:\/\/statorials.org\/nl\/r-maak-een-categorische-variabele-van-continue\/","title":{"rendered":"Hoe u een categorische variabele maakt, gaat verder in r"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">U kunt de functie <strong>cut()<\/strong> in R gebruiken om een categorische variabele te maken op basis van een continue variabele.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Deze functie gebruikt de volgende basissyntaxis:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>df$cat_variable &lt;- cut(df$continuous_variable,\n                       breaks=c(5, 10, 15, 20, 25),\n                       labels=c(' <span style=\"color: #ff0000;\">A<\/span> ', ' <span style=\"color: #ff0000;\">B<\/span> ', ' <span style=\"color: #ff0000;\">C<\/span> ', ' <span style=\"color: #ff0000;\">D<\/span> '))\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Houd er rekening mee dat <strong>breaks<\/strong> de waarden specificeren waardoor de continue variabele moet worden gedeeld, en dat <strong>labels<\/strong> het label specificeren dat aan de waarden van de nieuwe categorische variabele moet worden gegeven.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Het volgende voorbeeld laat zien hoe u deze syntaxis in de praktijk kunt gebruiken.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Voorbeeld: het cre\u00ebren van een categorische variabele vanuit een continu\u00fcm in R<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Stel dat we het volgende dataframe in R hebben:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008080;\">#create data frame\n<\/span>df &lt;- data. <span style=\"color: #3366ff;\">frame<\/span> (team=c('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'),\n                 points=c(78, 82, 86, 94, 99, 104, 109, 110))\n\n<span style=\"color: #008080;\">#view data frame\n<\/span>df\n\n  team points\n1 To 78\n2 B 82\n3 C 86\n4 D 94\n5 E 99\n6 F 104\n7 G 109\n8:11 a.m.\n<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Momenteel zijn <strong>punten<\/strong> een continue variabele.<\/span><\/p>\n<p> <span style=\"color: #000000;\">We kunnen de functie <strong>cut()<\/strong> gebruiken om het in een categorische variabele te knippen:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008080;\">#add new column that cuts 'points' into categories\n<\/span>df$cat &lt;- cut(df$points,\n              breaks=c(70, 80, 90, 100, 110),\n              labels=c('Bad', 'OK', 'Good', 'Great'))\n\n<span style=\"color: #008080;\">#view updated data frame\n<\/span>df\n\n  team points cat\n1 To 78 Bad\n2 B 82 OK\n3 C 86 OK\n4 D 94 Good\n5 E 99 Good\n6 F 104 Great\n7 G 109 Great\n8:110 Great<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">We hebben een nieuwe categorische variabele gemaakt met de naam <strong>cat<\/strong> , die elk team in het dataframe rangschikt als Slecht, OK, Goed of Uitstekend op basis van hun <strong>punten<\/strong> .<\/span><\/p>\n<p> <span style=\"color: #000000;\">We kunnen de functie <strong>class()<\/strong> gebruiken om de klasse van deze nieuwe variabele te controleren:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008080;\">#check class of 'cat' column\n<\/span>class(df$cat)\n\n[1] \u201cfactor\u201d\n<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">We zien dat de variabele <strong>kat<\/strong> een factor is.<\/span><\/p>\n<p> <span style=\"color: #000000;\">We kunnen ook de functie <strong>table()<\/strong> gebruiken om het aantal keren dat elke categorie in de <strong>cat-<\/strong> variabele voorkomt te tellen:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008080;\">#count occurrences of each category in 'cat' variable<\/span>\ntable(df$cat)\n  Bad OK Good Great \n    1 2 2 3<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Houd er rekening mee dat als u geen <strong>labels-<\/strong> argument voor de functie <strong>cut()<\/strong> opgeeft, R eenvoudigweg het bereik van intervalwaarden als labels zal gebruiken:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008080;\">#add new column that cuts 'points' into categories\n<\/span>df$cat &lt;- cut(df$points, breaks=c(70, 80, 90, 100, 110))\n\n<span style=\"color: #008080;\">#view updated data frame<\/span>\ndf\n\n  team points cat\n1 A 78 (70.80]\n2 B 82 (80.90]\n3 C 86 (80.90]\n4 D 94 (90,100]\n5 E 99 (90,100]\n6 F 104 (100,110]\n7 G 109 (100,110]\n8:110 (100,110]\n<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">In sommige gevallen geeft u er misschien de voorkeur aan om aangepaste labels te gebruiken.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Aanvullende bronnen<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">In de volgende tutorials wordt uitgelegd hoe u andere veelvoorkomende bewerkingen in R kunt uitvoeren:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/nl\/converteer-een-categorische-variabele-naar-numerieke-r\/\" target=\"_blank\" rel=\"noopener\">Hoe categorische variabelen naar numeriek te converteren in R<\/a><br \/> <a href=\"https:\/\/statorials.org\/nl\/maak-een-categorische-variabele-in-r\/\" target=\"_blank\" rel=\"noopener\">Hoe categorische variabelen te cre\u00ebren in R<\/a><br \/><a href=\"https:\/\/statorials.org\/nl\/plot-categorische-gegevens-in-r\/\" target=\"_blank\" rel=\"noopener\">Hoe categorische gegevens in R te plotten<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>U kunt de functie cut() in R gebruiken om een categorische variabele te maken op basis van een continue variabele. Deze functie gebruikt de volgende basissyntaxis: df$cat_variable &lt;- cut(df$continuous_variable, breaks=c(5, 10, 15, 20, 25), labels=c(&#8218; A &#8218;, &#8218; B &#8218;, &#8218; C &#8218;, &#8218; D &#8218;)) Houd er rekening mee dat breaks de waarden specificeren [&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-2575","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 een categorische variabele te cre\u00ebren vanuit een continu\u00fcm in R - Statorials<\/title>\n<meta name=\"description\" content=\"In deze tutorial wordt uitgelegd hoe u een categorische variabele kunt maken op basis van een continue variabele in R, 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\/r-maak-een-categorische-variabele-van-continue\/\" \/>\n<meta property=\"og:locale\" content=\"de_DE\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Hoe een categorische variabele te cre\u00ebren vanuit een continu\u00fcm in R - Statorials\" \/>\n<meta property=\"og:description\" content=\"In deze tutorial wordt uitgelegd hoe u een categorische variabele kunt maken op basis van een continue variabele in R, met verschillende voorbeelden.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/nl\/r-maak-een-categorische-variabele-van-continue\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-21T16:20:29+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\/r-maak-een-categorische-variabele-van-continue\/\",\"url\":\"https:\/\/statorials.org\/nl\/r-maak-een-categorische-variabele-van-continue\/\",\"name\":\"Hoe een categorische variabele te cre\u00ebren vanuit een continu\u00fcm in R - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/nl\/#website\"},\"datePublished\":\"2023-07-21T16:20:29+00:00\",\"dateModified\":\"2023-07-21T16:20:29+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219\"},\"description\":\"In deze tutorial wordt uitgelegd hoe u een categorische variabele kunt maken op basis van een continue variabele in R, met verschillende voorbeelden.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/nl\/r-maak-een-categorische-variabele-van-continue\/#breadcrumb\"},\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/nl\/r-maak-een-categorische-variabele-van-continue\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/nl\/r-maak-een-categorische-variabele-van-continue\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Thuis\",\"item\":\"https:\/\/statorials.org\/nl\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Hoe u een categorische variabele maakt, gaat verder in r\"}]},{\"@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 een categorische variabele te cre\u00ebren vanuit een continu\u00fcm in R - Statorials","description":"In deze tutorial wordt uitgelegd hoe u een categorische variabele kunt maken op basis van een continue variabele in R, 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\/r-maak-een-categorische-variabele-van-continue\/","og_locale":"de_DE","og_type":"article","og_title":"Hoe een categorische variabele te cre\u00ebren vanuit een continu\u00fcm in R - Statorials","og_description":"In deze tutorial wordt uitgelegd hoe u een categorische variabele kunt maken op basis van een continue variabele in R, met verschillende voorbeelden.","og_url":"https:\/\/statorials.org\/nl\/r-maak-een-categorische-variabele-van-continue\/","og_site_name":"Statorials","article_published_time":"2023-07-21T16:20:29+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\/r-maak-een-categorische-variabele-van-continue\/","url":"https:\/\/statorials.org\/nl\/r-maak-een-categorische-variabele-van-continue\/","name":"Hoe een categorische variabele te cre\u00ebren vanuit een continu\u00fcm in R - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/nl\/#website"},"datePublished":"2023-07-21T16:20:29+00:00","dateModified":"2023-07-21T16:20:29+00:00","author":{"@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219"},"description":"In deze tutorial wordt uitgelegd hoe u een categorische variabele kunt maken op basis van een continue variabele in R, met verschillende voorbeelden.","breadcrumb":{"@id":"https:\/\/statorials.org\/nl\/r-maak-een-categorische-variabele-van-continue\/#breadcrumb"},"inLanguage":"de","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/nl\/r-maak-een-categorische-variabele-van-continue\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/nl\/r-maak-een-categorische-variabele-van-continue\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Thuis","item":"https:\/\/statorials.org\/nl\/"},{"@type":"ListItem","position":2,"name":"Hoe u een categorische variabele maakt, gaat verder in r"}]},{"@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\/2575","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=2575"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts\/2575\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/media?parent=2575"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/categories?post=2575"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/tags?post=2575"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}