{"id":3057,"date":"2023-07-19T10:27:35","date_gmt":"2023-07-19T10:27:35","guid":{"rendered":"https:\/\/statorials.org\/nl\/r-argument-heeft-lengte-nul\/"},"modified":"2023-07-19T10:27:35","modified_gmt":"2023-07-19T10:27:35","slug":"r-argument-heeft-lengte-nul","status":"publish","type":"post","link":"https:\/\/statorials.org\/nl\/r-argument-heeft-lengte-nul\/","title":{"rendered":"Hoe op te lossen in r: argument heeft een lengte van nul"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Een foutmelding die u kunt tegenkomen bij het gebruik van R is:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>Error in if (x &lt; 10) {: argument is of length zero\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Deze fout treedt meestal op wanneer u probeert een logische vergelijking uit te voeren in een if-instructie in R, maar de variabele die u in de vergelijking gebruikt, heeft een lengte nul.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Twee voorbeelden van variabelen met lengte nul zijn <strong>numeriek()<\/strong> of <strong>Character(0)<\/strong> .<\/span><\/p>\n<p> <span style=\"color: #000000;\">Het volgende voorbeeld laat zien hoe u deze fout in de praktijk kunt oplossen.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Hoe de fout te reproduceren<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Stel dat we de volgende numerieke variabele in R cre\u00ebren met een lengte nul:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#create numeric variable with length of zero\n<span style=\"color: #000000;\">x &lt;- numeric()<\/span>\n<\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Stel nu dat we deze variabele proberen te gebruiken in<\/span> <span style=\"color: #000000;\">een if-instructie:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#if x is less than 10, print x to console\n<span style=\"color: #000000;\">if(x &lt; <span style=\"color: #008000;\">10<\/span> ) {\n  x\n}\n\nError in if (x &lt; 10) {: argument is of length zero\n<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">We ontvangen een foutmelding omdat de variabele die we defini\u00ebren een lengte van nul heeft.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Als we eenvoudigweg een numerieke variabele met een re\u00eble waarde zouden maken, zouden we deze foutmelding nooit ontvangen bij het gebruik van de if-instructie:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#create numeric variable\n<span style=\"color: #000000;\">y &lt;- 5<\/span>\n\n#if y is less than 10, print y to console\n<span style=\"color: #000000;\">if(y &lt; <span style=\"color: #008000;\">10<\/span> ) {\n  y\n}\n\n[1] 5\n<\/span><\/span><\/strong><\/pre>\n<h3> <span style=\"color: #000000;\"><strong>Hoe u de fout kunt vermijden<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Om de fout in de <strong>argumentlengte nul<\/strong> te voorkomen, moeten we een <strong>isTRUE-<\/strong> functie opnemen, die de volgende logica gebruikt:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\">is. <span style=\"color: #3366ff;\">logical<\/span> (x) &amp;&amp; length(x) == <span style=\"color: #008000;\">1<\/span> &amp;&amp; !is. <span style=\"color: #3366ff;\">na<\/span> (x) &amp;&amp; x<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Als we deze functie gebruiken in de if-instructie, krijgen we geen foutmelding bij het vergelijken van onze variabele met een waarde:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\">if(isTRUE(x) &amp;&amp; x &lt; <span style=\"color: #008000;\">10<\/span> ) {\n  x\n}\n<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">In plaats van een foutmelding te ontvangen, ontvangen we eenvoudigweg geen uitvoer omdat de functie <strong>isTRUE(x)<\/strong> evalueert naar <strong>FALSE<\/strong> , wat betekent dat de waarde van x nooit wordt afgedrukt.<\/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 fouten in R kunt oplossen:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/nl\/r-argumenten-impliceren-een-ander-aantal-regels\/\" target=\"_blank\" rel=\"noopener\">Hoe op te lossen in R: argumenten hebben betrekking op een verschillend aantal regels<\/a><br \/> <a href=\"https:\/\/statorials.org\/nl\/dplyr-fout-bij-het-selecteren-van-ongebruikte-argumenten\/\" target=\"_blank\" rel=\"noopener\">Hoe op te lossen in R: fout bij het selecteren van ongebruikte argumenten<\/a><br \/> <a href=\"https:\/\/statorials.org\/nl\/r-vervanging-op-lengte-nul\/\" target=\"_blank\" rel=\"noopener\">Hoe te repareren in R: vervanging heeft een lengte van nul<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Een foutmelding die u kunt tegenkomen bij het gebruik van R is: Error in if (x &lt; 10) {: argument is of length zero Deze fout treedt meestal op wanneer u probeert een logische vergelijking uit te voeren in een if-instructie in R, maar de variabele die u in de vergelijking gebruikt, heeft een lengte [&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-3057","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 op te lossen in R: argument heeft een lengte van nul - Statorials<\/title>\n<meta name=\"description\" content=\"In deze tutorial wordt uitgelegd hoe u de fout &#039;Argument is lengte nul&#039; in R kunt oplossen, inclusief 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-argument-heeft-lengte-nul\/\" \/>\n<meta property=\"og:locale\" content=\"de_DE\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Hoe op te lossen in R: argument heeft een lengte van nul - Statorials\" \/>\n<meta property=\"og:description\" content=\"In deze tutorial wordt uitgelegd hoe u de fout &#039;Argument is lengte nul&#039; in R kunt oplossen, inclusief voorbeelden.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/nl\/r-argument-heeft-lengte-nul\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-19T10:27:35+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-argument-heeft-lengte-nul\/\",\"url\":\"https:\/\/statorials.org\/nl\/r-argument-heeft-lengte-nul\/\",\"name\":\"Hoe op te lossen in R: argument heeft een lengte van nul - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/nl\/#website\"},\"datePublished\":\"2023-07-19T10:27:35+00:00\",\"dateModified\":\"2023-07-19T10:27:35+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219\"},\"description\":\"In deze tutorial wordt uitgelegd hoe u de fout &#39;Argument is lengte nul&#39; in R kunt oplossen, inclusief voorbeelden.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/nl\/r-argument-heeft-lengte-nul\/#breadcrumb\"},\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/nl\/r-argument-heeft-lengte-nul\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/nl\/r-argument-heeft-lengte-nul\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Thuis\",\"item\":\"https:\/\/statorials.org\/nl\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Hoe op te lossen in r: argument heeft een lengte van nul\"}]},{\"@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 op te lossen in R: argument heeft een lengte van nul - Statorials","description":"In deze tutorial wordt uitgelegd hoe u de fout &#39;Argument is lengte nul&#39; in R kunt oplossen, inclusief 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-argument-heeft-lengte-nul\/","og_locale":"de_DE","og_type":"article","og_title":"Hoe op te lossen in R: argument heeft een lengte van nul - Statorials","og_description":"In deze tutorial wordt uitgelegd hoe u de fout &#39;Argument is lengte nul&#39; in R kunt oplossen, inclusief voorbeelden.","og_url":"https:\/\/statorials.org\/nl\/r-argument-heeft-lengte-nul\/","og_site_name":"Statorials","article_published_time":"2023-07-19T10:27:35+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-argument-heeft-lengte-nul\/","url":"https:\/\/statorials.org\/nl\/r-argument-heeft-lengte-nul\/","name":"Hoe op te lossen in R: argument heeft een lengte van nul - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/nl\/#website"},"datePublished":"2023-07-19T10:27:35+00:00","dateModified":"2023-07-19T10:27:35+00:00","author":{"@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219"},"description":"In deze tutorial wordt uitgelegd hoe u de fout &#39;Argument is lengte nul&#39; in R kunt oplossen, inclusief voorbeelden.","breadcrumb":{"@id":"https:\/\/statorials.org\/nl\/r-argument-heeft-lengte-nul\/#breadcrumb"},"inLanguage":"de","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/nl\/r-argument-heeft-lengte-nul\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/nl\/r-argument-heeft-lengte-nul\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Thuis","item":"https:\/\/statorials.org\/nl\/"},{"@type":"ListItem","position":2,"name":"Hoe op te lossen in r: argument heeft een lengte van nul"}]},{"@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\/3057","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=3057"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts\/3057\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/media?parent=3057"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/categories?post=3057"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/tags?post=3057"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}