

{"id":5131,"date":"2017-03-10T10:36:13","date_gmt":"2017-03-10T15:36:13","guid":{"rendered":"https:\/\/rud.is\/b\/?p=5131"},"modified":"2018-03-10T07:53:58","modified_gmt":"2018-03-10T12:53:58","slug":"making-a-case-for-case_when","status":"publish","type":"post","link":"https:\/\/rud.is\/b\/2017\/03\/10\/making-a-case-for-case_when\/","title":{"rendered":"Making a Case for case_when"},"content":{"rendered":"<p>This is a brief (and likely obvious, for some folks) post on the <code>dplyr::case_when()<\/code> function.<\/p>\n<p>Part of my <a href=\"https:\/\/help.rapid7.com\/?community\">work<\/a>-work is dealing with data from internet scans. When we&#8217;re performing a deeper inspection of a particular internet protocol or service we try to capture as much system and service metadata as possible. Sifting through said metadata to find individual and collective insight is often a painful task given the diversity in the internet ecosystem.<\/p>\n<p>One attribute we try to collect in all our service scans is operating system (OS) version. For many of our minutiae-focused researchers, it&#8217;s vital to know if a host is using &#8220;CoreOS 899.17.0&#8221; vs &#8220;CoreOS 835.9.0&#8221;. For much of the aggregation and clustering work we do, &#8220;CoreOS&#8221; is just fine.<\/p>\n<p>In broad scans for any given service the OS diversity can be YUGE. There may be upwards of 10 different variations each of Windows, Red Hat, Ubuntu, Debian, et. al. present along with a smattering of very highly infrequent OS-types such as &#8220;Scientific Linux&#8221;. Plus, we can always count on probes returning <em>many<\/em> <code>NA<\/code> values for many discrete attribute queries, including OS type+version.<\/p>\n<p>There are many ways to reduce a diverse list of OS type+version strings to a reduced target set. <code>switch()<\/code> and <code>ifelse()<\/code> are likely go-to solutions for many of you reading this. If you are in those camps and haven&#8217;t tried <code>dplyr::case_when()<\/code> read on!<\/p>\n<h3>Noise Reduction<\/h3>\n<p>To illustrate the utility of <code>case_when()<\/code>, let&#8217;s walk through an example. I created a <em>tiny<\/em> excerpt of just the OS type + version info from 500 observations out of a much larger internet scan. You can find that data at <a href=\"https:\/\/rud.is\/dl\/os.txt\">https:\/\/rud.is\/dl\/os.txt<\/a>. Let&#8217;s take a look at the OS diversity:<\/p>\n<pre id=\"cw_01\"><code class=\"language-r\">library(ggalt)\r\nlibrary(hrbrthemes)\r\nlibrary(tidyverse)\r\n\r\nos &lt;- read_lines(&quot;https:\/\/rud.is\/dl\/os.txt&quot;, na = &quot;NA&quot;)\r\n\r\nstr(table(os, useNA = &quot;always&quot;))\r\n##  &#039;table&#039; int [1:28(1d)] 2 3 1 1 1 44 3 101 1 6 ...\r\n##  - attr(*, &quot;dimnames&quot;)=List of 1\r\n##   ..$ os: chr [1:28] &quot;&quot; &quot;&lt;unknown&gt;&quot; &quot;Amazon Linux AMI 2016.03&quot; &quot;Amazon Linux AMI 2016.09&quot; ...\r\n\r\nsort(unique(os))\r\n##  [1] &quot;&quot;                                           \r\n##  [2] &quot;&lt;unknown&gt;&quot;                                  \r\n##  [3] &quot;Amazon Linux AMI 2016.03&quot;                   \r\n##  [4] &quot;Amazon Linux AMI 2016.09&quot;                   \r\n##  [5] &quot;Arch Linux&quot;                                 \r\n##  [6] &quot;CentOS Linux 7 (Core)&quot;                      \r\n##  [7] &quot;CoreOS 766.4.0&quot;                             \r\n##  [8] &quot;CoreOS 899.17.0&quot;                            \r\n##  [9] &quot;Debian GNU\/Linux 7 (wheezy)&quot;                \r\n## [10] &quot;Debian GNU\/Linux 8 (jessie)&quot;                \r\n## [11] &quot;Fedora 20 (Heisenbug)&quot;                      \r\n## [12] &quot;linux&quot;                                      \r\n## [13] &quot;openSUSE Leap 42.2&quot;                         \r\n## [14] &quot;RancherOS v0.7.0&quot;                           \r\n## [15] &quot;Red Hat Enterprise Linux Server 7.2 (Maipo)&quot;\r\n## [16] &quot;Red Hat Enterprise Linux Server 7.3 (Maipo)&quot;\r\n## [17] &quot;Ubuntu 14.04.1 LTS&quot;                         \r\n## [18] &quot;Ubuntu 14.04.2 LTS&quot;                         \r\n## [19] &quot;Ubuntu 14.04.3 LTS&quot;                         \r\n## [20] &quot;Ubuntu 14.04.4 LTS&quot;                         \r\n## [21] &quot;Ubuntu 14.04.5 LTS&quot;                         \r\n## [22] &quot;Ubuntu 15.10&quot;                               \r\n## [23] &quot;Ubuntu 16.04.1 LTS&quot;                         \r\n## [24] &quot;Ubuntu 16.04.2 LTS&quot;                         \r\n## [25] &quot;Ubuntu 16.10&quot;                               \r\n## [26] &quot;Windows Server 2016 Datacenter&quot;             \r\n## [27] &quot;Windows Server 2016 Standard&quot;<\/code><\/pre>\n<p>There are 29 (including <code>NA<\/code>) different strings in just a tiny excerpt. Ugh.<\/p>\n<p>If we want to group all Windows results as &#8220;Windows&#8221;, all Red Hat, CentOS and Fedora results as &#8220;Fedora&#8221;, all Ubuntu and Debian results as &#8220;Debian&#8221; and all CoreOS and Amazon results as &#8220;Amazon&#8221; <em>while keeping<\/em> <code>NA<\/code>_s_ <code>NA<\/code> <em>and lumping everything else as &#8220;Other&#8221;<\/em> it&#8217;s super-easy with <code>case_when()<\/code>:<\/p>\n<pre id=\"cw_02\"><code class=\"language-r\">ELSE &lt;- TRUE\r\n\r\ncase_when(\r\n  grepl(&quot;Windows&quot;, os) ~ &quot;Windows-ish&quot;,\r\n  grepl(&quot;Red Hat|CentOS|Fedora&quot;, os) ~ &quot;Fedora-ish&quot;,\r\n  grepl(&quot;Ubuntu|Debian&quot;, os) ~ &quot;Debian-ish&quot;,\r\n  grepl(&quot;CoreOS|Amazon&quot;, os) ~ &quot;Amazon-ish&quot;,\r\n  is.na(os) ~ &quot;Unknown&quot;,\r\n  ELSE ~ &quot;Other&quot;\r\n) %&gt;%\r\n  table() %&gt;%\r\n  as_data_frame() %&gt;%\r\n  set_names(c(&quot;os&quot;, &quot;Node Count&quot;)) %&gt;%\r\n  arrange(`Node Count`) %&gt;%\r\n  mutate(os = factor(os, os)) %&gt;%\r\n  ggplot(aes(`Node Count`, os)) +\r\n  geom_lollipop(horizontal = TRUE, size=1.5, color=&quot;#54278f&quot;) +\r\n  scale_x_comma(limits=c(0,300)) +\r\n  labs(y=NULL, title=&quot;OS Types&quot;) +\r\n  theme_ipsum_rc(grid=&quot;X&quot;)<\/code><\/pre>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"5136\" data-permalink=\"https:\/\/rud.is\/b\/2017\/03\/10\/making-a-case-for-case_when\/cursor_and_rstudio-4\/\" data-orig-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2017\/03\/Cursor_and_RStudio.png?fit=1542%2C596&amp;ssl=1\" data-orig-size=\"1542,596\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Cursor_and_RStudio\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2017\/03\/Cursor_and_RStudio.png?fit=510%2C197&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2017\/03\/Cursor_and_RStudio.png?resize=510%2C197&#038;ssl=1\" alt=\"\" width=\"510\" height=\"197\" class=\"aligncenter size-full wp-image-5136\" \/><\/p>\n<p>The clever formula (<code>~<\/code>) syntax used by <code>case_when()<\/code> enables you to cleanly and effortlessly reduce factor\/categorical levels and also lets you preserve <code>NA<\/code> values (which I translated to &#8220;Unknown&#8221;). Since <code>ELSE<\/code> is <a href=\"https:\/\/dzone.com\/articles\/case-and-if-else-statement-sql\">used in the SQL <code>CASE<\/code> statement<\/a> and <code>dplyr::case_when()<\/code> is a riff of said SQL cousin, I like to use an assigned <code>ELSE<\/code> to make it more visually explicit, but using <code>TRUE<\/code> is just as good (and, perhaps, better since <code>TRUE<\/code> can&#8217;t get namespace clobbered like the <code>ELSE<\/code> variable can).<\/p>\n<h3>FIN<\/h3>\n<p>If you&#8217;re in sequential or nested <code>ifelse()<\/code> Hades or are frustrated by <code>switch()<\/code> limitations, give <code>dplyr::case_when()<\/code> a try for your next project.<\/p>\n<h3>Epilogue<\/h3>\n<p>Not enough time earlier to add other methods, so this hint from @drob will have to suffice for now:<\/p>\n<blockquote class=\"twitter-tweet\" data-lang=\"en\">\n<p lang=\"en\" dir=\"ltr\"><a href=\"https:\/\/mobile.twitter.com\/hrbrmstr\">@hrbrmstr<\/a> alternative: fuzzyjoin&#39;s regex_left_join? Advantages:<\/p>\n<p>1. regexes can be in config file<br \/>2. one string can match multiple regexes <a href=\"https:\/\/t.co\/9IavUTEDMJ\">pic.twitter.com\/9IavUTEDMJ<\/a><\/p>\n<p>&mdash; David Robinson (@drob) <a href=\"https:\/\/mobile.twitter.com\/drob\/status\/840232496860135424\">March 10, 2017<\/a><\/p><\/blockquote>\n<p><script async src=\"\/\/platform.twitter.com\/widgets.js\" charset=\"utf-8\"><\/script><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is a brief (and likely obvious, for some folks) post on the dplyr::case_when() function. Part of my work-work is dealing with data from internet scans. When we&#8217;re performing a deeper inspection of a particular internet protocol or service we try to capture as much system and service metadata as possible. Sifting through said metadata [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":5136,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":true,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":3,"activitypub_interaction_policy_quote":"anyone","activitypub_status":"","footnotes":""},"categories":[779,91],"tags":[810],"class_list":["post-5131","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dplyr","category-r","tag-post"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Making a Case for case_when - rud.is<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/rud.is\/b\/2017\/03\/10\/making-a-case-for-case_when\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Making a Case for case_when - rud.is\" \/>\n<meta property=\"og:description\" content=\"This is a brief (and likely obvious, for some folks) post on the dplyr::case_when() function. Part of my work-work is dealing with data from internet scans. When we&#8217;re performing a deeper inspection of a particular internet protocol or service we try to capture as much system and service metadata as possible. Sifting through said metadata [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/rud.is\/b\/2017\/03\/10\/making-a-case-for-case_when\/\" \/>\n<meta property=\"og:site_name\" content=\"rud.is\" \/>\n<meta property=\"article:published_time\" content=\"2017-03-10T15:36:13+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-03-10T12:53:58+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2017\/03\/Cursor_and_RStudio.png?fit=1542%2C596&ssl=1\" \/>\n\t<meta property=\"og:image:width\" content=\"1542\" \/>\n\t<meta property=\"og:image:height\" content=\"596\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"hrbrmstr\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"hrbrmstr\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2017\\\/03\\\/10\\\/making-a-case-for-case_when\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2017\\\/03\\\/10\\\/making-a-case-for-case_when\\\/\"},\"author\":{\"name\":\"hrbrmstr\",\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/#\\\/schema\\\/person\\\/d7cb7487ab0527447f7fda5c423ff886\"},\"headline\":\"Making a Case for case_when\",\"datePublished\":\"2017-03-10T15:36:13+00:00\",\"dateModified\":\"2018-03-10T12:53:58+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2017\\\/03\\\/10\\\/making-a-case-for-case_when\\\/\"},\"wordCount\":498,\"commentCount\":4,\"publisher\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/#\\\/schema\\\/person\\\/d7cb7487ab0527447f7fda5c423ff886\"},\"image\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2017\\\/03\\\/10\\\/making-a-case-for-case_when\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/rud.is\\\/b\\\/wp-content\\\/uploads\\\/2017\\\/03\\\/Cursor_and_RStudio.png?fit=1542%2C596&ssl=1\",\"keywords\":[\"post\"],\"articleSection\":[\"dplyr\",\"R\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/rud.is\\\/b\\\/2017\\\/03\\\/10\\\/making-a-case-for-case_when\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2017\\\/03\\\/10\\\/making-a-case-for-case_when\\\/\",\"url\":\"https:\\\/\\\/rud.is\\\/b\\\/2017\\\/03\\\/10\\\/making-a-case-for-case_when\\\/\",\"name\":\"Making a Case for case_when - rud.is\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2017\\\/03\\\/10\\\/making-a-case-for-case_when\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2017\\\/03\\\/10\\\/making-a-case-for-case_when\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/rud.is\\\/b\\\/wp-content\\\/uploads\\\/2017\\\/03\\\/Cursor_and_RStudio.png?fit=1542%2C596&ssl=1\",\"datePublished\":\"2017-03-10T15:36:13+00:00\",\"dateModified\":\"2018-03-10T12:53:58+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2017\\\/03\\\/10\\\/making-a-case-for-case_when\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/rud.is\\\/b\\\/2017\\\/03\\\/10\\\/making-a-case-for-case_when\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2017\\\/03\\\/10\\\/making-a-case-for-case_when\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/rud.is\\\/b\\\/wp-content\\\/uploads\\\/2017\\\/03\\\/Cursor_and_RStudio.png?fit=1542%2C596&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/rud.is\\\/b\\\/wp-content\\\/uploads\\\/2017\\\/03\\\/Cursor_and_RStudio.png?fit=1542%2C596&ssl=1\",\"width\":1542,\"height\":596},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2017\\\/03\\\/10\\\/making-a-case-for-case_when\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/rud.is\\\/b\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Making a Case for case_when\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/#website\",\"url\":\"https:\\\/\\\/rud.is\\\/b\\\/\",\"name\":\"rud.is\",\"description\":\"&quot;In God we trust. All others must bring data&quot;\",\"publisher\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/#\\\/schema\\\/person\\\/d7cb7487ab0527447f7fda5c423ff886\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/rud.is\\\/b\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/#\\\/schema\\\/person\\\/d7cb7487ab0527447f7fda5c423ff886\",\"name\":\"hrbrmstr\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/i0.wp.com\\\/rud.is\\\/b\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/ukr-shield.png?fit=460%2C460&ssl=1\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/rud.is\\\/b\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/ukr-shield.png?fit=460%2C460&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/rud.is\\\/b\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/ukr-shield.png?fit=460%2C460&ssl=1\",\"width\":460,\"height\":460,\"caption\":\"hrbrmstr\"},\"logo\":{\"@id\":\"https:\\\/\\\/i0.wp.com\\\/rud.is\\\/b\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/ukr-shield.png?fit=460%2C460&ssl=1\"},\"description\":\"Don't look at me\u2026I do what he does \u2014 just slower. #rstats avuncular \u2022 ?Resistance Fighter \u2022 Cook \u2022 Christian \u2022 [Master] Chef des Donn\u00e9es de S\u00e9curit\u00e9 @ @rapid7\",\"sameAs\":[\"http:\\\/\\\/rud.is\"],\"url\":\"https:\\\/\\\/rud.is\\\/b\\\/author\\\/hrbrmstr\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Making a Case for case_when - rud.is","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:\/\/rud.is\/b\/2017\/03\/10\/making-a-case-for-case_when\/","og_locale":"en_US","og_type":"article","og_title":"Making a Case for case_when - rud.is","og_description":"This is a brief (and likely obvious, for some folks) post on the dplyr::case_when() function. Part of my work-work is dealing with data from internet scans. When we&#8217;re performing a deeper inspection of a particular internet protocol or service we try to capture as much system and service metadata as possible. Sifting through said metadata [&hellip;]","og_url":"https:\/\/rud.is\/b\/2017\/03\/10\/making-a-case-for-case_when\/","og_site_name":"rud.is","article_published_time":"2017-03-10T15:36:13+00:00","article_modified_time":"2018-03-10T12:53:58+00:00","og_image":[{"width":1542,"height":596,"url":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2017\/03\/Cursor_and_RStudio.png?fit=1542%2C596&ssl=1","type":"image\/png"}],"author":"hrbrmstr","twitter_card":"summary_large_image","twitter_misc":{"Written by":"hrbrmstr","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/rud.is\/b\/2017\/03\/10\/making-a-case-for-case_when\/#article","isPartOf":{"@id":"https:\/\/rud.is\/b\/2017\/03\/10\/making-a-case-for-case_when\/"},"author":{"name":"hrbrmstr","@id":"https:\/\/rud.is\/b\/#\/schema\/person\/d7cb7487ab0527447f7fda5c423ff886"},"headline":"Making a Case for case_when","datePublished":"2017-03-10T15:36:13+00:00","dateModified":"2018-03-10T12:53:58+00:00","mainEntityOfPage":{"@id":"https:\/\/rud.is\/b\/2017\/03\/10\/making-a-case-for-case_when\/"},"wordCount":498,"commentCount":4,"publisher":{"@id":"https:\/\/rud.is\/b\/#\/schema\/person\/d7cb7487ab0527447f7fda5c423ff886"},"image":{"@id":"https:\/\/rud.is\/b\/2017\/03\/10\/making-a-case-for-case_when\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2017\/03\/Cursor_and_RStudio.png?fit=1542%2C596&ssl=1","keywords":["post"],"articleSection":["dplyr","R"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/rud.is\/b\/2017\/03\/10\/making-a-case-for-case_when\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/rud.is\/b\/2017\/03\/10\/making-a-case-for-case_when\/","url":"https:\/\/rud.is\/b\/2017\/03\/10\/making-a-case-for-case_when\/","name":"Making a Case for case_when - rud.is","isPartOf":{"@id":"https:\/\/rud.is\/b\/#website"},"primaryImageOfPage":{"@id":"https:\/\/rud.is\/b\/2017\/03\/10\/making-a-case-for-case_when\/#primaryimage"},"image":{"@id":"https:\/\/rud.is\/b\/2017\/03\/10\/making-a-case-for-case_when\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2017\/03\/Cursor_and_RStudio.png?fit=1542%2C596&ssl=1","datePublished":"2017-03-10T15:36:13+00:00","dateModified":"2018-03-10T12:53:58+00:00","breadcrumb":{"@id":"https:\/\/rud.is\/b\/2017\/03\/10\/making-a-case-for-case_when\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/rud.is\/b\/2017\/03\/10\/making-a-case-for-case_when\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/rud.is\/b\/2017\/03\/10\/making-a-case-for-case_when\/#primaryimage","url":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2017\/03\/Cursor_and_RStudio.png?fit=1542%2C596&ssl=1","contentUrl":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2017\/03\/Cursor_and_RStudio.png?fit=1542%2C596&ssl=1","width":1542,"height":596},{"@type":"BreadcrumbList","@id":"https:\/\/rud.is\/b\/2017\/03\/10\/making-a-case-for-case_when\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/rud.is\/b\/"},{"@type":"ListItem","position":2,"name":"Making a Case for case_when"}]},{"@type":"WebSite","@id":"https:\/\/rud.is\/b\/#website","url":"https:\/\/rud.is\/b\/","name":"rud.is","description":"&quot;In God we trust. All others must bring data&quot;","publisher":{"@id":"https:\/\/rud.is\/b\/#\/schema\/person\/d7cb7487ab0527447f7fda5c423ff886"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/rud.is\/b\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/rud.is\/b\/#\/schema\/person\/d7cb7487ab0527447f7fda5c423ff886","name":"hrbrmstr","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2023\/10\/ukr-shield.png?fit=460%2C460&ssl=1","url":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2023\/10\/ukr-shield.png?fit=460%2C460&ssl=1","contentUrl":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2023\/10\/ukr-shield.png?fit=460%2C460&ssl=1","width":460,"height":460,"caption":"hrbrmstr"},"logo":{"@id":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2023\/10\/ukr-shield.png?fit=460%2C460&ssl=1"},"description":"Don't look at me\u2026I do what he does \u2014 just slower. #rstats avuncular \u2022 ?Resistance Fighter \u2022 Cook \u2022 Christian \u2022 [Master] Chef des Donn\u00e9es de S\u00e9curit\u00e9 @ @rapid7","sameAs":["http:\/\/rud.is"],"url":"https:\/\/rud.is\/b\/author\/hrbrmstr\/"}]}},"jetpack_featured_media_url":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2017\/03\/Cursor_and_RStudio.png?fit=1542%2C596&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/p23idr-1kL","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":11648,"url":"https:\/\/rud.is\/b\/2018\/11\/14\/use-github-vulnerability-alerts-to-keep-users-of-your-r-packages-safe\/","url_meta":{"origin":5131,"position":0},"title":"Use GitHub Vulnerability Alerts to Keep Users of Your R Packages Safe","author":"hrbrmstr","date":"2018-11-14","format":false,"excerpt":"Despite their now inherent evil status, GitHub has some tools other repository aggregators do not. One such tool is the free vulnerability alert service which will scan repositories for outdated+vulnerable dependencies. Now, \"R\" is nowhere near a first-class citizen in the internet writ large, including software development tooling (e.g. the\u2026","rel":"","context":"In &quot;Cybersecurity&quot;","block_context":{"text":"Cybersecurity","link":"https:\/\/rud.is\/b\/category\/cybersecurity\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2018\/11\/Screen-Shot-2018-11-14-at-08.43.14.png?fit=1200%2C424&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2018\/11\/Screen-Shot-2018-11-14-at-08.43.14.png?fit=1200%2C424&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2018\/11\/Screen-Shot-2018-11-14-at-08.43.14.png?fit=1200%2C424&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2018\/11\/Screen-Shot-2018-11-14-at-08.43.14.png?fit=1200%2C424&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2018\/11\/Screen-Shot-2018-11-14-at-08.43.14.png?fit=1200%2C424&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":10257,"url":"https:\/\/rud.is\/b\/2018\/05\/08\/wrangling-data-table-out-of-the-fbi-2017-ic3-crime-report\/","url_meta":{"origin":5131,"position":1},"title":"Wrangling Data Table Out Of the FBI 2017 IC3 Crime Report","author":"hrbrmstr","date":"2018-05-08","format":false,"excerpt":"The U.S. FBI Internet Crime Complaint Center was established in 2000 to receive complaints of Internet crime. They produce an annual report, just released 2017's edition, and I need the data from it. Since I have to wrangle it out, I thought some folks might like to play long at\u2026","rel":"","context":"In &quot;R&quot;","block_context":{"text":"R","link":"https:\/\/rud.is\/b\/category\/r\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2018\/05\/ic3_victim_treemap-1.png?fit=1200%2C771&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2018\/05\/ic3_victim_treemap-1.png?fit=1200%2C771&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2018\/05\/ic3_victim_treemap-1.png?fit=1200%2C771&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2018\/05\/ic3_victim_treemap-1.png?fit=1200%2C771&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2018\/05\/ic3_victim_treemap-1.png?fit=1200%2C771&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":12103,"url":"https:\/\/rud.is\/b\/2019\/03\/19\/assumptions-matter-more-than-dependencies\/","url_meta":{"origin":5131,"position":2},"title":"Assumptions Matter More Than Dependencies","author":"hrbrmstr","date":"2019-03-19","format":false,"excerpt":"There's been alot of talk about \"dependencies\" in the R universe of late. This is not really a post about that but more of a \"really, don't do this\" if you decide you want to poke the dependency bear by trying to build a deeply flawed model off of CRAN\u2026","rel":"","context":"In &quot;R&quot;","block_context":{"text":"R","link":"https:\/\/rud.is\/b\/category\/r\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":13533,"url":"https:\/\/rud.is\/b\/2022\/08\/19\/bootstrapping-an-ojs-quarto-document-with-an-observable-notebook\/","url_meta":{"origin":5131,"position":3},"title":"Bootstrapping An {ojs} Quarto Document With An Observable Notebook","author":"hrbrmstr","date":"2022-08-19","format":false,"excerpt":"Quarto is amazing! And, it's eating the world! OK. Perhaps not the entire world. But it's still amazing! If you browse around the HQ, you'll find many interesting notebooks. You may even have a few yourself! Wouldn't it be great if you could just import an Observable notebook right into\u2026","rel":"","context":"In &quot;Quarto&quot;","block_context":{"text":"Quarto","link":"https:\/\/rud.is\/b\/category\/quarto\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":12138,"url":"https:\/\/rud.is\/b\/2019\/04\/10\/lost-in-sql-translation-charting-dbplyr-mapped-sql-function-support-across-all-backends\/","url_meta":{"origin":5131,"position":4},"title":"Lost In [SQL] Translation: Charting d[b]plyr Mapped SQL Function Support Across All Backends","author":"hrbrmstr","date":"2019-04-10","format":false,"excerpt":"Like more posts than I care to admit, this one starts innocently enough with a tweet by @gshotwell: Is there a reference document somewhere of which dplyr commands work on various database backends? #rstats\u2014 Gordon Shotwell (@gshotwell) April 9, 2019 Since I use at least 4 different d[b]plyr backends every\u2026","rel":"","context":"In &quot;dplyr&quot;","block_context":{"text":"dplyr","link":"https:\/\/rud.is\/b\/category\/dplyr\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2019\/04\/backend-heatmap.jpg?fit=1200%2C659&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2019\/04\/backend-heatmap.jpg?fit=1200%2C659&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2019\/04\/backend-heatmap.jpg?fit=1200%2C659&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2019\/04\/backend-heatmap.jpg?fit=1200%2C659&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2019\/04\/backend-heatmap.jpg?fit=1200%2C659&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":11392,"url":"https:\/\/rud.is\/b\/2018\/08\/16\/updates-to-the-sergeant-apache-drill-connector-package-apache-drill-1-14-0-release\/","url_meta":{"origin":5131,"position":5},"title":"Updates to the sergeant (Apache Drill connector) Package &#038; a look at Apache Drill 1.14.0 release","author":"hrbrmstr","date":"2018-08-16","format":false,"excerpt":"Apache Drill 1.14.0 was recently released, bringing with it many new features and a temporary incompatibility with the current rev of the MapR ODBC drivers. The Drill community expects new ODBC drivers to arrive shortly. The sergeant? is an alternative to ODBC for R users as it provides a dplyr\u2026","rel":"","context":"In &quot;Apache Drill&quot;","block_context":{"text":"Apache Drill","link":"https:\/\/rud.is\/b\/category\/apache-drill\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/posts\/5131","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/comments?post=5131"}],"version-history":[{"count":0,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/posts\/5131\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/media\/5136"}],"wp:attachment":[{"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/media?parent=5131"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/categories?post=5131"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/tags?post=5131"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}