{"id":3053,"date":"2023-07-19T10:53:04","date_gmt":"2023-07-19T10:53:04","guid":{"rendered":"https:\/\/statorials.org\/nl\/r-ncol-functie\/"},"modified":"2023-07-19T10:53:04","modified_gmt":"2023-07-19T10:53:04","slug":"r-ncol-functie","status":"publish","type":"post","link":"https:\/\/statorials.org\/nl\/r-ncol-functie\/","title":{"rendered":"Hoe de ncol-functie in r te gebruiken (met voorbeelden)"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">U kunt de functie <strong>ncol()<\/strong> in R gebruiken om het aantal kolommen in een dataframe of matrix te tellen.<\/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>ncol(x)<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Goud:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\"><strong>x<\/strong> : Naam van het dataframe of de matrix<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">De volgende voorbeelden laten zien hoe u deze functie in verschillende scenario&#8217;s kunt gebruiken.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Voorbeeld 1: Gebruik ncol om het aantal kolommen in het dataframe te tellen<\/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;\">#create data frame<\/span>\ndf &lt;- data. <span style=\"color: #3366ff;\">frame<\/span> (team=c('A', 'B', 'C', 'D', 'E'),\n                 points=c(99, 90, 86, 88, 95),\n                 assists=c(33, 28, 31, 39, 34),\n                 rebounds=c(30, 28, 24, 24, 28))\n\n<span style=\"color: #008080;\">#view data frame\n<\/span>df\n\n  team points assists rebounds\n1 A 99 33 30\n2 B 90 28 28\n3 C 86 31 24\n4 D 88 39 24\n5 E 95 34 28\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">We kunnen de functie <strong>ncol()<\/strong> gebruiken om het totale aantal kolommen in het dataframe weer te geven:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#display number of columns in data frame<\/span>\nncol(df)\n\n[1] 4\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\"><span style=\"color: #000000;\">Uit het resultaat kunnen we zien dat er in totaal <strong>4<\/strong> kolommen in het dataframe zijn.<\/span><\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Voorbeeld 2: Gebruik ncol om het aantal kolommen in de matrix te tellen<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Stel dat we de volgende matrix in R hebben:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#create matrix\n<span style=\"color: #000000;\">mat &lt;- matrix(1:21, nrow= <span style=\"color: #008000;\">3<\/span> )\n<\/span>\n#view matrix\n<span style=\"color: #000000;\">mast\n\n     [,1] [,2] [,3] [,4] [,5] [,6] [,7]\n[1,] 1 4 7 10 13 16 19\n[2,] 2 5 8 11 14 17 20\n[3,] 3 6 9 12 15 18 21<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">We kunnen de functie <strong>ncol()<\/strong> gebruiken om het totale aantal kolommen in de matrix weer te geven:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#display number of columns in matrix<\/span>\nncol(mat)\n\n[1] 7\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Uit het resultaat kunnen we zien dat er in totaal <strong>7<\/strong> kolommen in de matrix zijn.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Wanneer moet u de ncol-functie in de praktijk gebruiken?<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">In de praktijk gebruiken we vaak de <strong>ncol-<\/strong> functie wanneer we voor het eerst een nieuwe dataset in R laden, zodat we snel inzicht krijgen in de grootte van een dataset.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Deze functie wordt vaak gebruikt met <strong>nrow<\/strong> , wat ons het aantal rijen in een bepaalde dataset vertelt.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Om snel het aantal kolommen <em>en<\/em> rijen in een dataset weer te geven, kunt u de <strong>dim-<\/strong> functie gebruiken, die de afmetingen van een dataset retourneert in termen van het aantal kolommen en rijen.<\/span><\/p>\n<p> <span style=\"color: #000000;\">De volgende code laat zien hoe u deze functies kunt gebruiken met een dataframe in R:<\/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('A', 'B', 'C', 'D', 'E'),\n                 points=c(99, 90, 86, 88, 95),\n                 assists=c(33, 28, 31, 39, 34),\n                 rebounds=c(30, 28, 24, 24, 28))\n\n<span style=\"color: #008080;\">#display number of rows\n<span style=\"color: #000000;\">nrow(df)<\/span>\n\n<span style=\"color: #000000;\">[1] 5<\/span>\n\n#display number of columns<\/span>\nncol(df)\n\n[1] 4\n\n<span style=\"color: #008080;\">#display dimensions<\/span>\ndim(df)\n\n[1] 5 4\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Uit het resultaat kunnen we zien dat dit dataframe <strong>5<\/strong> rijen en <strong>4<\/strong> kolommen heeft.<\/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 taken in R kunt uitvoeren:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/nl\/nrow-functie-in-r\/\" target=\"_blank\" rel=\"noopener\">Hoe de nrow-functie in R te gebruiken<\/a><br \/><a href=\"https:\/\/statorials.org\/nl\/r-selecteer-specifieke-kolommen\/\" target=\"_blank\" rel=\"noopener\">Hoe specifieke kolommen in R te selecteren<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>U kunt de functie ncol() in R gebruiken om het aantal kolommen in een dataframe of matrix te tellen. Deze functie gebruikt de volgende basissyntaxis: ncol(x) Goud: x : Naam van het dataframe of de matrix De volgende voorbeelden laten zien hoe u deze functie in verschillende scenario&#8217;s kunt gebruiken. Voorbeeld 1: Gebruik ncol om [&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-3053","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 de ncol-functie in R te gebruiken (met voorbeelden) \u2013 Statorials<\/title>\n<meta name=\"description\" content=\"In deze tutorial wordt uitgelegd hoe je de ncol-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\/r-ncol-functie\/\" \/>\n<meta property=\"og:locale\" content=\"de_DE\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Hoe de ncol-functie in R te gebruiken (met voorbeelden) \u2013 Statorials\" \/>\n<meta property=\"og:description\" content=\"In deze tutorial wordt uitgelegd hoe je de ncol-functie in R gebruikt, met verschillende voorbeelden.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/nl\/r-ncol-functie\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-19T10:53:04+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-ncol-functie\/\",\"url\":\"https:\/\/statorials.org\/nl\/r-ncol-functie\/\",\"name\":\"Hoe de ncol-functie in R te gebruiken (met voorbeelden) \u2013 Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/nl\/#website\"},\"datePublished\":\"2023-07-19T10:53:04+00:00\",\"dateModified\":\"2023-07-19T10:53:04+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219\"},\"description\":\"In deze tutorial wordt uitgelegd hoe je de ncol-functie in R gebruikt, met verschillende voorbeelden.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/nl\/r-ncol-functie\/#breadcrumb\"},\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/nl\/r-ncol-functie\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/nl\/r-ncol-functie\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Thuis\",\"item\":\"https:\/\/statorials.org\/nl\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Hoe de ncol-functie 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 de ncol-functie in R te gebruiken (met voorbeelden) \u2013 Statorials","description":"In deze tutorial wordt uitgelegd hoe je de ncol-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\/r-ncol-functie\/","og_locale":"de_DE","og_type":"article","og_title":"Hoe de ncol-functie in R te gebruiken (met voorbeelden) \u2013 Statorials","og_description":"In deze tutorial wordt uitgelegd hoe je de ncol-functie in R gebruikt, met verschillende voorbeelden.","og_url":"https:\/\/statorials.org\/nl\/r-ncol-functie\/","og_site_name":"Statorials","article_published_time":"2023-07-19T10:53:04+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-ncol-functie\/","url":"https:\/\/statorials.org\/nl\/r-ncol-functie\/","name":"Hoe de ncol-functie in R te gebruiken (met voorbeelden) \u2013 Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/nl\/#website"},"datePublished":"2023-07-19T10:53:04+00:00","dateModified":"2023-07-19T10:53:04+00:00","author":{"@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219"},"description":"In deze tutorial wordt uitgelegd hoe je de ncol-functie in R gebruikt, met verschillende voorbeelden.","breadcrumb":{"@id":"https:\/\/statorials.org\/nl\/r-ncol-functie\/#breadcrumb"},"inLanguage":"de","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/nl\/r-ncol-functie\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/nl\/r-ncol-functie\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Thuis","item":"https:\/\/statorials.org\/nl\/"},{"@type":"ListItem","position":2,"name":"Hoe de ncol-functie 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\/3053","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=3053"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts\/3053\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/media?parent=3053"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/categories?post=3053"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/tags?post=3053"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}