{"id":1813,"date":"2023-07-24T21:34:45","date_gmt":"2023-07-24T21:34:45","guid":{"rendered":"https:\/\/statorials.org\/nl\/dist-functie-in-r\/"},"modified":"2023-07-24T21:34:45","modified_gmt":"2023-07-24T21:34:45","slug":"dist-functie-in-r","status":"publish","type":"post","link":"https:\/\/statorials.org\/nl\/dist-functie-in-r\/","title":{"rendered":"Hoe de dist-functie in r te gebruiken (met voorbeelden)"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">De functie <strong>dist()<\/strong> in R kan worden gebruikt om een afstandsmatrix te berekenen, die de afstanden tussen rijen in een matrix of dataframe weergeeft.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Deze functie gebruikt de volgende basissyntaxis:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>dist(x, methode=\u201dEuclidisch\u201d)<\/strong><\/span><\/p>\n<p> <span style=\"color: #000000;\">Goud:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\"><strong>x:<\/strong> de naam van het matrix- of datablok.<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>methode:<\/strong> de te gebruiken afstandsmeting. De standaardinstelling is &#8222;Euclidisch&#8220;, maar de opties omvatten &#8222;maximum&#8220;, &#8222;manhattan&#8220;, &#8222;canberra&#8220;, &#8222;binary&#8220; of &#8222;minkowski&#8220;.<\/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 dataframe:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#define four vectors\n<\/span>a &lt;- c(2, 4, 4, 6)\nb &lt;- c(5, 5, 7, 8)\nc &lt;- c(9, 9, 9, 8)\nd &lt;- c(1, 2, 3, 3)\n\n<span style=\"color: #008080;\">#row bind four vectors into matrix\n<\/span>mat &lt;- rbind(a, b, c, d)\n\n<span style=\"color: #008080;\">#view matrix\n<\/span>mast\n\n  [,1] [,2] [,3] [,4]\na 2 4 4 6\nb 5 5 7 8\nc 9 9 9 8\nd 1 2 3 3<\/strong><\/pre>\n<h3> <span style=\"color: #000000;\"><strong>Voorbeeld 1: Gebruik dist() om de Euclidische afstand te berekenen<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">De <strong>Euclidische afstand<\/strong> tussen twee vectoren A en B wordt als volgt berekend:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Euclidische afstand = \u221a <span style=\"border-top: 1px solid black;\">\u03a3(A <sub>i<\/sub> -B <sub>i<\/sub> ) <sup>2<\/sup><\/span><\/strong><\/span><\/p>\n<p> <span style=\"color: #000000;\">De volgende code laat zien hoe je een afstandsmatrix berekent die de Euclidische afstand tussen elke rij van een matrix in R weergeeft:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#calculate Euclidean distance between each row in matrix\n<\/span>dist(mat)\n\n          ABC\nb4.795832                    \nc 10.148892 6.000000          \nd 3.872983 8.124038 13.190906\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Zo interpreteert u het resultaat:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\">De Euclidische afstand tussen lijn a en lijn b is <strong>4,795832<\/strong> .<\/span><\/li>\n<li> <span style=\"color: #000000;\">De Euclidische afstand tussen lijn a en lijn c is <strong>10,148892<\/strong> .<\/span><\/li>\n<li> <span style=\"color: #000000;\">De Euclidische afstand tussen lijn a en lijn d is <strong>3,872983<\/strong> .<\/span><\/li>\n<li> <span style=\"color: #000000;\">De Euclidische afstand tussen lijn b en lijn c is <strong>6,000000<\/strong> .<\/span><\/li>\n<li> <span style=\"color: #000000;\">De Euclidische afstand tussen lijn b en lijn d is <strong>8,124038<\/strong> .<\/span><\/li>\n<li> <span style=\"color: #000000;\">De Euclidische afstand tussen lijn c en lijn d is <strong>13,190906<\/strong> .<\/span><\/li>\n<\/ul>\n<h3> <span style=\"color: #000000;\"><strong>Voorbeeld 2: Gebruik dist() om de maximale afstand te berekenen<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">De <strong>maximale afstand<\/strong> tussen twee vectoren, A en B, wordt berekend als het maximale verschil tussen alle paarsgewijze elementen.<\/span><\/p>\n<p> <span style=\"color: #000000;\">De volgende code laat zien hoe je een afstandsmatrix berekent die de maximale afstand tussen elke rij van een matrix in R weergeeft:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#calculate Maximum distance between each row in matrix\n<\/span>dist(mat, method=\" <span style=\"color: #ff0000;\">maximum<\/span> \")\n\n  ABC\nb 3    \nc 7 4  \nd 3 5 8<\/strong><\/pre>\n<h3> <span style=\"color: #000000;\"><strong>Voorbeeld 3: Gebruik dist() om de afstand vanaf Canberra te berekenen<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">De <strong>Canberra-afstand<\/strong> tussen twee vectoren A en B wordt als volgt berekend:<br \/><\/span><\/p>\n<p> <strong><span style=\"color: #000000;\">Afstand vanaf Canberra = \u03a3 |A <sub>i<\/sub> -B <sub>i<\/sub> | \/ | <sub>AI<\/sub> | + | <sub>Bje<\/sub> |<\/span><\/strong><\/p>\n<p> <span style=\"color: #000000;\">De volgende code laat zien hoe je een afstandsmatrix berekent die de Canberra-afstand tussen elke rij van een matrix in R weergeeft:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#calculate Canberra distance between each row in matrix\n<\/span>dist(mat, method=\" <span style=\"color: #ff0000;\">canberra<\/span> \")\n\n          ABC\nb 0.9552670                    \nc 1.5484515 0.6964286          \nd 1.1428571 1.9497835 2.3909091<\/strong><\/pre>\n<h3> <span style=\"color: #000000;\"><strong>Voorbeeld 4: Gebruik dist() om de binaire afstand te berekenen<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">De <strong>binaire afstand<\/strong> tussen twee vectoren, A en B, wordt berekend als het aandeel elementen dat de twee vectoren delen.<\/span><\/p>\n<p> <span style=\"color: #000000;\">De volgende code laat zien hoe je een afstandsmatrix berekent die de binaire afstand tussen elke rij van een matrix in R weergeeft:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#calculate Binary distance between each row in matrix\n<\/span>dist(mat, method=\" <span style=\"color: #ff0000;\">binary<\/span> \")\n\n  ABC\nb 0    \nc 0 0  \nd 0 0 0<\/strong><\/pre>\n<h3> <span style=\"color: #000000;\"><strong>Voorbeeld 5: Gebruik dist() om de Minkowski-afstand te berekenen<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">De <strong>Minkowski-afstand<\/strong> tussen twee vectoren A en B wordt als volgt berekend:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Minkowski-afstand = (\u03a3|a <sub>i<\/sub> \u2013 b <sub>i<\/sub> | <sup>p<\/sup> ) <sup>1\/p<\/sup><\/strong><\/span><\/p>\n<p> <span style=\"color: #000000;\">waarbij <em>i<\/em> het i- <sup>de<\/sup> element van elke vector is en <em>p<\/em> een geheel getal is.<\/span><\/p>\n<p> <span style=\"color: #000000;\">De volgende code laat zien hoe je een afstandsmatrix berekent die de Minkowski-afstand toont (met behulp van p=3) tussen elke rij van een matrix in R:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#calculate Minkowski distance between each row in matrix\n<\/span>dist(mat, method=\" <span style=\"color: #ff0000;\">minkowski<\/span> \", p= <span style=\"color: #008000;\">3<\/span> )\n\n          ABC\nb 3.979057                    \nc 8.439010 5.142563          \nd 3.332222 6.542133 10.614765<\/strong><\/pre>\n<h3> <span style=\"color: #000000;\"><strong>Aanvullende bronnen<\/strong><\/span><\/h3>\n<p> <a href=\"https:\/\/statorials.org\/nl\/jaccard-overeenkomst-in-r\/\" target=\"_blank\" rel=\"noopener\">Hoe Jaccard-gelijkenis in R te berekenen<\/a><br \/> <a href=\"https:\/\/statorials.org\/nl\/cosinus-gelijkenis-r\/\" target=\"_blank\" rel=\"noopener\">Hoe cosinusovereenkomst in R te berekenen<\/a><br \/> <a href=\"https:\/\/statorials.org\/nl\/puntproduct-in-r\/\" target=\"_blank\" rel=\"noopener\">Hoe het puntproduct in R te berekenen<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>De functie dist() in R kan worden gebruikt om een afstandsmatrix te berekenen, die de afstanden tussen rijen in een matrix of dataframe weergeeft. Deze functie gebruikt de volgende basissyntaxis: dist(x, methode=\u201dEuclidisch\u201d) Goud: x: de naam van het matrix- of datablok. methode: de te gebruiken afstandsmeting. De standaardinstelling is &#8222;Euclidisch&#8220;, maar de opties omvatten &#8222;maximum&#8220;, [&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-1813","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 dist-functie in R te gebruiken (met voorbeelden) \u2013 Statorials<\/title>\n<meta name=\"description\" content=\"In deze tutorial wordt uitgelegd hoe je de dist-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\/dist-functie-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 dist-functie in R te gebruiken (met voorbeelden) \u2013 Statorials\" \/>\n<meta property=\"og:description\" content=\"In deze tutorial wordt uitgelegd hoe je de dist-functie in R gebruikt, met verschillende voorbeelden.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/nl\/dist-functie-in-r\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-24T21:34:45+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=\"3\u00a0Minuten\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/nl\/dist-functie-in-r\/\",\"url\":\"https:\/\/statorials.org\/nl\/dist-functie-in-r\/\",\"name\":\"Hoe de dist-functie in R te gebruiken (met voorbeelden) \u2013 Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/nl\/#website\"},\"datePublished\":\"2023-07-24T21:34:45+00:00\",\"dateModified\":\"2023-07-24T21:34:45+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219\"},\"description\":\"In deze tutorial wordt uitgelegd hoe je de dist-functie in R gebruikt, met verschillende voorbeelden.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/nl\/dist-functie-in-r\/#breadcrumb\"},\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/nl\/dist-functie-in-r\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/nl\/dist-functie-in-r\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Thuis\",\"item\":\"https:\/\/statorials.org\/nl\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Hoe de dist-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 dist-functie in R te gebruiken (met voorbeelden) \u2013 Statorials","description":"In deze tutorial wordt uitgelegd hoe je de dist-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\/dist-functie-in-r\/","og_locale":"de_DE","og_type":"article","og_title":"Hoe de dist-functie in R te gebruiken (met voorbeelden) \u2013 Statorials","og_description":"In deze tutorial wordt uitgelegd hoe je de dist-functie in R gebruikt, met verschillende voorbeelden.","og_url":"https:\/\/statorials.org\/nl\/dist-functie-in-r\/","og_site_name":"Statorials","article_published_time":"2023-07-24T21:34:45+00:00","author":"Dr.benjamin anderson","twitter_card":"summary_large_image","twitter_misc":{"Verfasst von":"Dr.benjamin anderson","Gesch\u00e4tzte Lesezeit":"3\u00a0Minuten"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/nl\/dist-functie-in-r\/","url":"https:\/\/statorials.org\/nl\/dist-functie-in-r\/","name":"Hoe de dist-functie in R te gebruiken (met voorbeelden) \u2013 Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/nl\/#website"},"datePublished":"2023-07-24T21:34:45+00:00","dateModified":"2023-07-24T21:34:45+00:00","author":{"@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219"},"description":"In deze tutorial wordt uitgelegd hoe je de dist-functie in R gebruikt, met verschillende voorbeelden.","breadcrumb":{"@id":"https:\/\/statorials.org\/nl\/dist-functie-in-r\/#breadcrumb"},"inLanguage":"de","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/nl\/dist-functie-in-r\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/nl\/dist-functie-in-r\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Thuis","item":"https:\/\/statorials.org\/nl\/"},{"@type":"ListItem","position":2,"name":"Hoe de dist-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\/1813","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=1813"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts\/1813\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/media?parent=1813"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/categories?post=1813"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/tags?post=1813"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}