{"id":5661,"date":"2015-11-23T23:55:34","date_gmt":"2015-11-23T22:55:34","guid":{"rendered":"http:\/\/emilkirkegaard.dk\/en\/?p=5661"},"modified":"2015-11-23T23:55:34","modified_gmt":"2015-11-23T22:55:34","slug":"kirkegaard-df_add_delta","status":"publish","type":"post","link":"https:\/\/emilkirkegaard.dk\/en\/2015\/11\/kirkegaard-df_add_delta\/","title":{"rendered":"kirkegaard: df_add_delta()"},"content":{"rendered":"<p><em>One idea for a series of blog posts is that I could about new functions in my R package. Often I just push these without letting anyone know, but I guess it could be useful to make an introduction for them (the more interesting ones anyway) here.<\/em><\/p>\n<p><strong>Function description:<\/strong> Adds delta (difference) columns to a data.frame. These are made from one primary variable and a number of secondary variables. Variables can be given either by indices or by name. If no secondary variables are given, all numeric variables are used.<\/p>\n<p>Example.<\/p>\n<pre id=\"rstudio_console_output\" class=\"GEM3DMTCFGB\" tabindex=\"0\"><span class=\"GEM3DMTCLGB ace_keyword\">&gt; <\/span><span class=\"GEM3DMTCLFB ace_keyword\">iris %&gt;% head %&gt;% df_add_delta(1)\r\n<\/span>  Sepal.Length Sepal.Width Petal.Length Petal.Width Species delta_Sepal.Length_Sepal.Width\r\n1          5.1         3.5          1.4         0.2  setosa                            1.6\r\n2          4.9         3.0          1.4         0.2  setosa                            1.9\r\n3          4.7         3.2          1.3         0.2  setosa                            1.5\r\n4          4.6         3.1          1.5         0.2  setosa                            1.5\r\n5          5.0         3.6          1.4         0.2  setosa                            1.4\r\n6          5.4         3.9          1.7         0.4  setosa                            1.5\r\n  delta_Sepal.Length_Petal.Length delta_Sepal.Length_Petal.Width\r\n1                             3.7                            4.9\r\n2                             3.5                            4.7\r\n3                             3.4                            4.5\r\n4                             3.1                            4.4\r\n5                             3.6                            4.8\r\n6                             3.7                            5.0<\/pre>\n<p class=\"GEM3DMTCFGB\" tabindex=\"0\">So, we see that three variables were created based on a prefix and a separator (both configurable). The difference scores are given in natural units, but can also be standardized automatically if desired.<\/p>\n<p class=\"GEM3DMTCFGB\" tabindex=\"0\">Three delta vars were made because we chose var 1 as the primary and it automatically selects the remaining numeric vars as secondaries.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One idea for a series of blog posts is that I could about new functions in my R package. Often I just push these without letting anyone know, but I guess it could be useful to make an introduction for them (the more interesting ones anyway) here. Function description: Adds delta (difference) columns to a [&hellip;]<\/p>\n","protected":false},"author":17,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2089],"tags":[2259,1979],"class_list":["post-5661","post","type-post","status-publish","format-standard","hentry","category-programming","tag-kirkegaard-package","tag-r","entry"],"_links":{"self":[{"href":"https:\/\/emilkirkegaard.dk\/en\/wp-json\/wp\/v2\/posts\/5661","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/emilkirkegaard.dk\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/emilkirkegaard.dk\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/emilkirkegaard.dk\/en\/wp-json\/wp\/v2\/users\/17"}],"replies":[{"embeddable":true,"href":"https:\/\/emilkirkegaard.dk\/en\/wp-json\/wp\/v2\/comments?post=5661"}],"version-history":[{"count":1,"href":"https:\/\/emilkirkegaard.dk\/en\/wp-json\/wp\/v2\/posts\/5661\/revisions"}],"predecessor-version":[{"id":5662,"href":"https:\/\/emilkirkegaard.dk\/en\/wp-json\/wp\/v2\/posts\/5661\/revisions\/5662"}],"wp:attachment":[{"href":"https:\/\/emilkirkegaard.dk\/en\/wp-json\/wp\/v2\/media?parent=5661"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/emilkirkegaard.dk\/en\/wp-json\/wp\/v2\/categories?post=5661"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/emilkirkegaard.dk\/en\/wp-json\/wp\/v2\/tags?post=5661"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}