{"id":3872,"date":"2023-07-15T01:38:08","date_gmt":"2023-07-15T01:38:08","guid":{"rendered":"https:\/\/statorials.org\/nl\/r-controleer-of-het-dataframe-leeg-is\/"},"modified":"2023-07-15T01:38:08","modified_gmt":"2023-07-15T01:38:08","slug":"r-controleer-of-het-dataframe-leeg-is","status":"publish","type":"post","link":"https:\/\/statorials.org\/nl\/r-controleer-of-het-dataframe-leeg-is\/","title":{"rendered":"Hoe te controleren of het dataframe leeg is in r (met voorbeeld)"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">De snelste manier om te controleren of een dataframe leeg is in R is door de functie <strong>nrow()<\/strong> te gebruiken:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>nrow(df)<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Deze functie retourneert het aantal rijen in een gegevensframe.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Als de functie 0 retourneert, is het dataframe leeg.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Als u wilt controleren of een dataframe leeg is in een if else-functie, kunt u hiervoor de volgende syntaxis gebruiken:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#create if else statement that checks if data frame is empty\n<\/span><span style=\"color: #008000;\">if<\/span> (nrow(df) <span style=\"color: #800080;\">==<\/span> 0){\n  <span style=\"color: #008000;\">print<\/span> (\u201c <span style=\"color: #ff0000;\">This data frame is empty<\/span> \u201d)\n} <span style=\"color: #008000;\">else<\/span> {\n  <span style=\"color: #008000;\">print<\/span> (\u201c <span style=\"color: #ff0000;\">This data frame is not empty<\/span> \u201d)\n}\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Het volgende voorbeeld laat zien hoe u in de praktijk kunt controleren of een dataframe leeg is.<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Gerelateerd:<\/strong> <a href=\"https:\/\/statorials.org\/nl\/nrow-functie-in-r\/\" target=\"_blank\" rel=\"noopener\">Een inleiding tot de nrow-functie in R (met voorbeelden)<\/a><\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Voorbeeld: controleer of het dataframe leeg is in R<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\"><span style=\"color: #000000;\">Stel dat we het volgende dataframe in R maken dat drie kolommen heeft maar volledig leeg is:<\/span><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#create empty data frame\n<\/span>df &lt;- data. <span style=\"color: #3366ff;\">frame<\/span> (player = character(),\n                 points = numeric(),\n                 assists = numeric())\n\n<span style=\"color: #008080;\">#view data frame\n<\/span>df\n\n[1] player points assists\n&lt;0 rows&gt; (or 0-length row.names)<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">We kunnen de functie <strong>nrow()<\/strong> gebruiken om het aantal rijen in het dataframe te controleren:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#display number of rows in data frame\n<\/span>nrow(df)\n\n[1] 0\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Omdat de functie 0 retourneert, vertelt dit ons dat het dataframe leeg is.<\/span><\/p>\n<p> <span style=\"color: #000000;\">We kunnen ook de volgende if else-instructie gebruiken om ons te vertellen of het dataframe leeg is of niet:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#create if else statement that checks if data frame is empty\n<\/span><span style=\"color: #008000;\">if<\/span> (nrow(df) <span style=\"color: #800080;\">==<\/span> 0){\n  <span style=\"color: #008000;\">print<\/span> (\u201c <span style=\"color: #ff0000;\">This data frame is empty<\/span> \u201d)\n} <span style=\"color: #008000;\">else<\/span> {\n  <span style=\"color: #008000;\">print<\/span> (\u201c <span style=\"color: #ff0000;\">This data frame is not empty<\/span> \u201d)\n}\n\n[1] \u201cThis data frame is empty\u201d\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Uit de uitvoer kunnen we zien dat het dataframe inderdaad leeg is.<\/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 R kunt uitvoeren:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/nl\/maak-een-leeg-dataframe-in-r\/\" target=\"_blank\" rel=\"noopener\">Hoe maak je een leeg dataframe in R<\/a><br \/> <a href=\"https:\/\/statorials.org\/nl\/voeg-een-lege-kolom-toe-aan-dataframe-r\/\" target=\"_blank\" rel=\"noopener\">Hoe u een lege kolom aan een dataframe toevoegt in R<\/a><br \/> <a href=\"https:\/\/statorials.org\/nl\/verwijder-lege-regels-in-r\/\" target=\"_blank\" rel=\"noopener\">Hoe lege regels uit het dataframe in R te verwijderen<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>De snelste manier om te controleren of een dataframe leeg is in R is door de functie nrow() te gebruiken: nrow(df) Deze functie retourneert het aantal rijen in een gegevensframe. Als de functie 0 retourneert, is het dataframe leeg. Als u wilt controleren of een dataframe leeg is in een if else-functie, kunt u hiervoor [&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-3872","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 u kunt controleren of het dataframe leeg is in R (met voorbeeld) - Statorials<\/title>\n<meta name=\"description\" content=\"In deze tutorial wordt uitgelegd hoe u kunt controleren of een dataframe leeg is 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-controleer-of-het-dataframe-leeg-is\/\" \/>\n<meta property=\"og:locale\" content=\"de_DE\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Hoe u kunt controleren of het dataframe leeg is in R (met voorbeeld) - Statorials\" \/>\n<meta property=\"og:description\" content=\"In deze tutorial wordt uitgelegd hoe u kunt controleren of een dataframe leeg is in R, met verschillende voorbeelden.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/nl\/r-controleer-of-het-dataframe-leeg-is\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-15T01:38:08+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-controleer-of-het-dataframe-leeg-is\/\",\"url\":\"https:\/\/statorials.org\/nl\/r-controleer-of-het-dataframe-leeg-is\/\",\"name\":\"Hoe u kunt controleren of het dataframe leeg is in R (met voorbeeld) - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/nl\/#website\"},\"datePublished\":\"2023-07-15T01:38:08+00:00\",\"dateModified\":\"2023-07-15T01:38:08+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219\"},\"description\":\"In deze tutorial wordt uitgelegd hoe u kunt controleren of een dataframe leeg is in R, met verschillende voorbeelden.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/nl\/r-controleer-of-het-dataframe-leeg-is\/#breadcrumb\"},\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/nl\/r-controleer-of-het-dataframe-leeg-is\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/nl\/r-controleer-of-het-dataframe-leeg-is\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Thuis\",\"item\":\"https:\/\/statorials.org\/nl\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Hoe te controleren of het dataframe leeg is in r (met voorbeeld)\"}]},{\"@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 u kunt controleren of het dataframe leeg is in R (met voorbeeld) - Statorials","description":"In deze tutorial wordt uitgelegd hoe u kunt controleren of een dataframe leeg is 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-controleer-of-het-dataframe-leeg-is\/","og_locale":"de_DE","og_type":"article","og_title":"Hoe u kunt controleren of het dataframe leeg is in R (met voorbeeld) - Statorials","og_description":"In deze tutorial wordt uitgelegd hoe u kunt controleren of een dataframe leeg is in R, met verschillende voorbeelden.","og_url":"https:\/\/statorials.org\/nl\/r-controleer-of-het-dataframe-leeg-is\/","og_site_name":"Statorials","article_published_time":"2023-07-15T01:38:08+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-controleer-of-het-dataframe-leeg-is\/","url":"https:\/\/statorials.org\/nl\/r-controleer-of-het-dataframe-leeg-is\/","name":"Hoe u kunt controleren of het dataframe leeg is in R (met voorbeeld) - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/nl\/#website"},"datePublished":"2023-07-15T01:38:08+00:00","dateModified":"2023-07-15T01:38:08+00:00","author":{"@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219"},"description":"In deze tutorial wordt uitgelegd hoe u kunt controleren of een dataframe leeg is in R, met verschillende voorbeelden.","breadcrumb":{"@id":"https:\/\/statorials.org\/nl\/r-controleer-of-het-dataframe-leeg-is\/#breadcrumb"},"inLanguage":"de","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/nl\/r-controleer-of-het-dataframe-leeg-is\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/nl\/r-controleer-of-het-dataframe-leeg-is\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Thuis","item":"https:\/\/statorials.org\/nl\/"},{"@type":"ListItem","position":2,"name":"Hoe te controleren of het dataframe leeg is in r (met voorbeeld)"}]},{"@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\/3872","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=3872"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts\/3872\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/media?parent=3872"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/categories?post=3872"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/tags?post=3872"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}