{"id":2983,"date":"2023-07-19T19:08:39","date_gmt":"2023-07-19T19:08:39","guid":{"rendered":"https:\/\/statorials.org\/nl\/leesregels-in-r\/"},"modified":"2023-07-19T19:08:39","modified_gmt":"2023-07-19T19:08:39","slug":"leesregels-in-r","status":"publish","type":"post","link":"https:\/\/statorials.org\/nl\/leesregels-in-r\/","title":{"rendered":"Hoe de readlines()-functie in r te gebruiken (met voorbeelden)"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">De functie <strong>readLines()<\/strong> in R kan worden gebruikt om alle of een deel van de tekstregels van een verbindingsobject te lezen.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Deze functie gebruikt de volgende syntaxis:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong>readLines(con, n=-1L)<\/strong><\/span><\/pre>\n<p> <span style=\"color: #000000;\">Goud:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\"><strong>nadeel:<\/strong> een verbindingsobject of een tekenreeks<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>n:<\/strong> Het maximale aantal te lezen regels. De standaardinstelling is om alle regels te lezen.<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">De volgende voorbeelden laten zien hoe u deze functie in de praktijk kunt gebruiken met het volgende tekstbestand genaamd <strong>some_data.txt<\/strong> :<\/span> <\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-25801\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/lignes-de-lecture1.jpg\" alt=\"readLines-functie in R\" width=\"470\" height=\"340\" srcset=\"\" sizes=\"auto, \"><\/p>\n<h3> <strong><span style=\"color: #000000;\">Voorbeeld 1: Gebruik readLines() om alle regels uit een tekstbestand te lezen<\/span><\/strong><\/h3>\n<p> <span style=\"color: #000000;\">Laten we zeggen dat het tekstbestand is opgeslagen in mijn map <strong>Documenten<\/strong> op mijn computer.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Ik kan de volgende functie <strong>readLines()<\/strong> gebruiken om elke regel uit dit tekstbestand te lezen:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #008080;\">#read every line from some_data.txt\n<\/span>readLines(\"C:\/Users\/Bob\/Documents\/some_data.txt\")\n\n[1] \u201cThe first line of the file\u201d \u201cThe second line of the file\u201d\n[3] \u201cThe third line of the file\u201d \u201cThe fourth line of the file\u201d\n[5] \"The fifth line of the file\" \"The sixth line of the file\"  \n<\/strong><\/span><\/pre>\n<p> <span style=\"color: #000000;\">Het tekstbestand bevat 6 regels, dus de functie <strong>readLines()<\/strong> produceert een tekenvector met lengte 6.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Als ik wil, kan ik in plaats daarvan de regels van het tekstbestand in een dataframe opslaan:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #008080;\">#read every line from some_data.txt\n<\/span>my_data &lt;- readLines(\"C:\/Users\/Bob\/Documents\/some_data.txt\")\n\n<span style=\"color: #008080;\">#create data frame\n<\/span>df = data. <span style=\"color: #3366ff;\">frame<\/span> (values=my_data)\n\n<span style=\"color: #008080;\">#view data frame\n<\/span>df\n\n                       values\n1 The first line of the file\n2 The second line of the file\n3 The third line of the file\n4 The fourth line of the file\n5 The fifth line of the file\n6 The sixth line of the file<\/strong><\/span><\/pre>\n<p> <span style=\"color: #000000;\">Het resultaat is een dataframe met \u00e9\u00e9n kolom en zes rijen.<\/span><\/p>\n<h3> <strong><span style=\"color: #000000;\">Voorbeeld 2: Gebruik readLines() om de eerste N regels van een tekstbestand te lezen<\/span><\/strong><\/h3>\n<p> <span style=\"color: #000000;\">Laten we er opnieuw van uitgaan dat het tekstbestand is opgeslagen in mijn map <strong>Documenten<\/strong> op mijn computer.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Ik kan de volgende functie <strong>readLines()<\/strong> met argument <strong>n<\/strong> gebruiken om alleen de eerste n regels van dit tekstbestand te lezen:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #008080;\">#read first 4 lines from some_data.txt\n<\/span>readLines(\"C:\/Users\/Bob\/Documents\/some_data.txt\", n= <span style=\"color: #008000;\">4<\/span> )\n\n[1] \u201cThe first line of the file\u201d \u201cThe second line of the file\u201d\n[3] \u201cThe third line of the file\u201d \u201cThe fourth line of the file\u201d\n<\/strong><\/span><\/pre>\n<p> <span style=\"color: #000000;\">De functie <strong>readLines()<\/strong> produceert een tekenvector met lengte 4.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Ik kan ook vierkante haakjes gebruiken om naar een specifieke regel in dit tekstbestand te navigeren.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Ik kan bijvoorbeeld de volgende code gebruiken om alleen toegang te krijgen tot de tweede regel van de tekenvector:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #008080;\">#read first 4 lines from some_data.txt\n<\/span>my_data &lt;- readLines(\"C:\/Users\/Bob\/Documents\/some_data.txt\", n= <span style=\"color: #008000;\">4<\/span> )\n\n<span style=\"color: #008080;\">#display second line only\n<\/span>my_data[2]\n\n[1] \"The second line of the file\"\n<\/strong><\/span><\/pre>\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 bestandstypen in R kunt importeren:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/nl\/r-leestafel\/\" target=\"_blank\" rel=\"noopener\">Lees.table gebruiken in R<\/a><br \/> <a href=\"https:\/\/statorials.org\/nl\/csv-importeren-in-r\/\" target=\"_blank\" rel=\"noopener\">CSV-bestanden importeren in R<\/a><br \/> <a href=\"https:\/\/statorials.org\/nl\/excel-importeren-in-r\/\" target=\"_blank\" rel=\"noopener\">Excel-bestanden importeren in R<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>De functie readLines() in R kan worden gebruikt om alle of een deel van de tekstregels van een verbindingsobject te lezen. Deze functie gebruikt de volgende syntaxis: readLines(con, n=-1L) Goud: nadeel: een verbindingsobject of een tekenreeks n: Het maximale aantal te lezen regels. De standaardinstelling is om alle regels te lezen. De volgende voorbeelden laten [&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-2983","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 functie readLines() in R te gebruiken (met voorbeelden) - Statorials<\/title>\n<meta name=\"description\" content=\"In deze tutorial wordt uitgelegd hoe u de functie readLines() 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\/leesregels-in-r\/\" \/>\n<meta property=\"og:locale\" content=\"de_DE\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Hoe de functie readLines() in R te gebruiken (met voorbeelden) - Statorials\" \/>\n<meta property=\"og:description\" content=\"In deze tutorial wordt uitgelegd hoe u de functie readLines() in R gebruikt, met verschillende voorbeelden.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/nl\/leesregels-in-r\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-19T19:08:39+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/lignes-de-lecture1.jpg\" \/>\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\/leesregels-in-r\/\",\"url\":\"https:\/\/statorials.org\/nl\/leesregels-in-r\/\",\"name\":\"Hoe de functie readLines() in R te gebruiken (met voorbeelden) - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/nl\/#website\"},\"datePublished\":\"2023-07-19T19:08:39+00:00\",\"dateModified\":\"2023-07-19T19:08:39+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219\"},\"description\":\"In deze tutorial wordt uitgelegd hoe u de functie readLines() in R gebruikt, met verschillende voorbeelden.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/nl\/leesregels-in-r\/#breadcrumb\"},\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/nl\/leesregels-in-r\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/nl\/leesregels-in-r\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Thuis\",\"item\":\"https:\/\/statorials.org\/nl\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Hoe de readlines()-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 functie readLines() in R te gebruiken (met voorbeelden) - Statorials","description":"In deze tutorial wordt uitgelegd hoe u de functie readLines() 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\/leesregels-in-r\/","og_locale":"de_DE","og_type":"article","og_title":"Hoe de functie readLines() in R te gebruiken (met voorbeelden) - Statorials","og_description":"In deze tutorial wordt uitgelegd hoe u de functie readLines() in R gebruikt, met verschillende voorbeelden.","og_url":"https:\/\/statorials.org\/nl\/leesregels-in-r\/","og_site_name":"Statorials","article_published_time":"2023-07-19T19:08:39+00:00","og_image":[{"url":"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/lignes-de-lecture1.jpg"}],"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\/leesregels-in-r\/","url":"https:\/\/statorials.org\/nl\/leesregels-in-r\/","name":"Hoe de functie readLines() in R te gebruiken (met voorbeelden) - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/nl\/#website"},"datePublished":"2023-07-19T19:08:39+00:00","dateModified":"2023-07-19T19:08:39+00:00","author":{"@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219"},"description":"In deze tutorial wordt uitgelegd hoe u de functie readLines() in R gebruikt, met verschillende voorbeelden.","breadcrumb":{"@id":"https:\/\/statorials.org\/nl\/leesregels-in-r\/#breadcrumb"},"inLanguage":"de","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/nl\/leesregels-in-r\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/nl\/leesregels-in-r\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Thuis","item":"https:\/\/statorials.org\/nl\/"},{"@type":"ListItem","position":2,"name":"Hoe de readlines()-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\/2983","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=2983"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts\/2983\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/media?parent=2983"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/categories?post=2983"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/tags?post=2983"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}