{"id":2906,"date":"2023-07-20T04:06:18","date_gmt":"2023-07-20T04:06:18","guid":{"rendered":"https:\/\/statorials.org\/nl\/bronfunctie-in-r\/"},"modified":"2023-07-20T04:06:18","modified_gmt":"2023-07-20T04:06:18","slug":"bronfunctie-in-r","status":"publish","type":"post","link":"https:\/\/statorials.org\/nl\/bronfunctie-in-r\/","title":{"rendered":"Hoe de bronfunctie in r te gebruiken (met voorbeeld)"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\"><span style=\"color: #000000;\">U kunt de <strong>bronfunctie<\/strong> in R gebruiken om functies die u in een ander R-script maakt, opnieuw te gebruiken.<\/span><\/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><span style=\"color: #3366ff;\">source<\/span> (\"path\/to\/some\/file.R\")<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Voeg deze regel gewoon bovenaan uw R-script toe en u kunt alle functies gebruiken die zijn gedefinieerd in <strong>file.R.<\/strong><\/span><\/p>\n<p> <span style=\"color: #000000;\">Het volgende voorbeeld laat zien hoe u de <strong>bronfunctie<\/strong> in de praktijk kunt gebruiken.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Voorbeeld: gebruik van de bronfunctie in R<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Stel dat we het volgende R-script hebben met de naam <strong>some_functions.R<\/strong> , dat twee eenvoudige, door de gebruiker gedefinieerde functies bevat:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #339966;\"><span style=\"color: #000000;\"><span style=\"color: #008080;\">#define function that divides values by 2\n<span style=\"color: #000000;\">divide_by_two &lt;- <span style=\"color: #008000;\">function<\/span> (x) {\n  <span style=\"color: #008000;\">return<\/span> (x\/2)\n}<\/span>\n\n#define function that multiplies values by 3\n<span style=\"color: #000000;\">multiply_by_three &lt;- <span style=\"color: #008000;\">function<\/span> (x) {\n  <span style=\"color: #008000;\">return<\/span> (x*3)\n}\n<\/span><\/span><\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Laten we nu zeggen dat we momenteel werken met een R-script genaamd <strong>main_script.R<\/strong> .<\/span><\/p>\n<p> <span style=\"color: #000000;\">Ervan uitgaande dat <strong>some_functions.R<\/strong> en <strong>main_script.R<\/strong> zich in dezelfde map bevinden, kunnen we source bovenaan ons <strong>main_script.R<\/strong> gebruiken om ons in staat te stellen de functies te gebruiken die we hebben gedefinieerd in het <strong>some_functions.R-<\/strong> script:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #3366ff;\">source<\/span> (\"some_functions.R\")\n\n<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'),\n                 points=c(14, 19, 22, 15, 30, 40))\n\n<span style=\"color: #008080;\">#view data frame\n<\/span>df\n\n  team points\n1 to 14\n2 B 19\n3 C 22\n4 D 15\n5 E 30\n6 F 40\n\n<span style=\"color: #008080;\">#create new columns using functions from some_functions.R\n<\/span>df$half_points &lt;- divide_by_two(df$points)\n\ndf$triple_points &lt;- multiply_by_three(df$points)\n\n<span style=\"color: #008080;\">#view updated data frame\n<\/span>df\n\n  team points half_points triple_points\n1 A 14 7.0 42\n2 B 19 9.5 57\n3 C 22 11.0 66\n4 D 15 7.5 45\n5 E 30 15.0 90\n6 F 40 20.0 120\n<\/strong><\/span><\/pre>\n<p> <span style=\"color: #000000;\">Merk op dat we twee nieuwe kolommen in ons dataframe kunnen maken met behulp van de functies die we hebben gedefinieerd in het <strong>some_functions.R-<\/strong> script.<\/span><\/p>\n<p> <span style=\"color: #000000;\"><span style=\"color: #000000;\">Dankzij de <strong>bronfunctie<\/strong> konden we de functies <strong>Divide_by_Two<\/strong> en <strong>Multiplier_by_Three<\/strong> in ons huidige script gebruiken, ook al waren deze functies niet in het huidige script gemaakt.<\/span><\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Opmerking<\/strong> : in dit voorbeeld hebben we slechts \u00e9\u00e9n <strong>bronfunctie<\/strong> bovenaan het bestand gebruikt. We kunnen echter zoveel <strong>bronfuncties<\/strong> gebruiken als we willen als we functies willen hergebruiken die in verschillende scripts zijn gedefinieerd.<\/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 functies in R kunt gebruiken:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/nl\/zie-functie-in-r\/\" target=\"_blank\" rel=\"noopener\">Hoe de View()-functie in R te gebruiken<\/a><br \/> <a href=\"https:\/\/statorials.org\/nl\/totale-r\/\" target=\"_blank\" rel=\"noopener\">Hoe de functie Aggregate() in R te gebruiken<\/a><br \/> <a href=\"https:\/\/statorials.org\/nl\/vervang-functie-in-r\/\" target=\"_blank\" rel=\"noopener\">Hoe de functie Replace() in R te gebruiken<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>U kunt de bronfunctie in R gebruiken om functies die u in een ander R-script maakt, opnieuw te gebruiken. Deze functie gebruikt de volgende basissyntaxis: source (&#8222;path\/to\/some\/file.R&#8220;) Voeg deze regel gewoon bovenaan uw R-script toe en u kunt alle functies gebruiken die zijn gedefinieerd in file.R. Het volgende voorbeeld laat zien hoe u de bronfunctie [&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-2906","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 bronfunctie in R te gebruiken (met voorbeeld) - Statorials<\/title>\n<meta name=\"description\" content=\"In deze tutorial wordt uitgelegd hoe u de bronfunctie in R gebruikt, inclusief een volledig voorbeeld.\" \/>\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\/bronfunctie-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 bronfunctie in R te gebruiken (met voorbeeld) - Statorials\" \/>\n<meta property=\"og:description\" content=\"In deze tutorial wordt uitgelegd hoe u de bronfunctie in R gebruikt, inclusief een volledig voorbeeld.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/nl\/bronfunctie-in-r\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-20T04:06:18+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\/bronfunctie-in-r\/\",\"url\":\"https:\/\/statorials.org\/nl\/bronfunctie-in-r\/\",\"name\":\"Hoe de bronfunctie in R te gebruiken (met voorbeeld) - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/nl\/#website\"},\"datePublished\":\"2023-07-20T04:06:18+00:00\",\"dateModified\":\"2023-07-20T04:06:18+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219\"},\"description\":\"In deze tutorial wordt uitgelegd hoe u de bronfunctie in R gebruikt, inclusief een volledig voorbeeld.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/nl\/bronfunctie-in-r\/#breadcrumb\"},\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/nl\/bronfunctie-in-r\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/nl\/bronfunctie-in-r\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Thuis\",\"item\":\"https:\/\/statorials.org\/nl\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Hoe de bronfunctie in r te gebruiken (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 de bronfunctie in R te gebruiken (met voorbeeld) - Statorials","description":"In deze tutorial wordt uitgelegd hoe u de bronfunctie in R gebruikt, inclusief een volledig voorbeeld.","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\/bronfunctie-in-r\/","og_locale":"de_DE","og_type":"article","og_title":"Hoe de bronfunctie in R te gebruiken (met voorbeeld) - Statorials","og_description":"In deze tutorial wordt uitgelegd hoe u de bronfunctie in R gebruikt, inclusief een volledig voorbeeld.","og_url":"https:\/\/statorials.org\/nl\/bronfunctie-in-r\/","og_site_name":"Statorials","article_published_time":"2023-07-20T04:06:18+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\/bronfunctie-in-r\/","url":"https:\/\/statorials.org\/nl\/bronfunctie-in-r\/","name":"Hoe de bronfunctie in R te gebruiken (met voorbeeld) - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/nl\/#website"},"datePublished":"2023-07-20T04:06:18+00:00","dateModified":"2023-07-20T04:06:18+00:00","author":{"@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219"},"description":"In deze tutorial wordt uitgelegd hoe u de bronfunctie in R gebruikt, inclusief een volledig voorbeeld.","breadcrumb":{"@id":"https:\/\/statorials.org\/nl\/bronfunctie-in-r\/#breadcrumb"},"inLanguage":"de","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/nl\/bronfunctie-in-r\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/nl\/bronfunctie-in-r\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Thuis","item":"https:\/\/statorials.org\/nl\/"},{"@type":"ListItem","position":2,"name":"Hoe de bronfunctie in r te gebruiken (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\/2906","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=2906"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts\/2906\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/media?parent=2906"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/categories?post=2906"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/tags?post=2906"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}