{"id":229,"date":"2019-02-10T03:53:54","date_gmt":"2019-02-10T03:53:54","guid":{"rendered":"http:\/\/mribeirodantas.xyz\/blog\/?p=229"},"modified":"2019-02-25T16:45:46","modified_gmt":"2019-02-25T16:45:46","slug":"the-unintended-trap-of-brackets-subsetting-in-r","status":"publish","type":"post","link":"https:\/\/mribeirodantas.xyz\/blog\/index.php\/2019\/02\/10\/the-unintended-trap-of-brackets-subsetting-in-r\/","title":{"rendered":"The unintended trap in bracket subsetting in R"},"content":{"rendered":"<span class=\"span-reading-time rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\"><b>Reading time: <\/span> <span class=\"rt-time\"> 3<\/span> <span class=\"rt-label rt-postfix\">minutes<\/b><\/span><\/span>\n<pre class=\"wp-block-preformatted\">The silent [and maybe mortal?] trap in bracket subsetting.<br><\/pre>\n\n\n\n<p>Dear reader,<br><br>It should be clear to you that, as several other programming languages, R provides different ways to tackle the same problem. One common problem in data analysis is to subset your data frame and, as <a href=\"https:\/\/www.google.com\/search?q=different+ways+of+subsetting+in+R&amp;oq=differen&amp;aqs=chrome.0.69i59j69i60l3j69i57j69i59.1519j0j7&amp;sourceid=chrome&amp;ie=UTF-8\">Google can show you<\/a>, there are several blog posts and articles trying to teach you different ways to subset your data frame in R. Let&#8217;s do a quick review here:<\/p>\n\n\n\n<p>Before starting to subset a data frame, we must first create one. I will create a data frame of patients named <em>var_example<\/em> with two columns, one for <em>vital&nbsp;status<\/em> (is_alive) and one for <em>birth&nbsp;year<\/em> (birthyear). Birth year values are 4-digit numbers representing the year of birth. The is_alive column can have one of three values:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li> TRUE: The person is alive;<\/li><li>FALSE: The person is dead;<\/li><li>NA: We do not know if this person is either alive or dead.<\/li><\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">> var_example &lt;- cbind(as.data.frame(sample(c(NA, TRUE, FALSE),\n                                          size=100,\n                                          replace=TRUE,\n                                          prob = c(0.1, 0.5, 0.4))),\n                     as.data.frame(sample(c(1980:1995),\n                                          size=100,\n                                          replace=TRUE)))\n> colnames(var_example) &lt;- c(\"is_alive\", \"birthyear\")<\/pre>\n\n\n\n<!--more-->\n\n\n\n<h3 class=\"wp-block-heading\">(1) Subset function<\/h3>\n\n\n\n<p>The <em>subset function<\/em> is probably the first function a non-experienced R developer would guess. If I&#8217;m looking for the number of alive patients and I want to use the <em>subset&nbsp;function<\/em>, I would type:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">> nrow(subset(var_example, is_alive == TRUE))\n[1] 48<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">(2) Which function<\/h3>\n\n\n\n<p>The <em>which function<\/em> is also very famous. If I&#8217;m looking for the number of alive patients and I want to use the <em>which&nbsp;function<\/em>, I would type:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">> length(which(var_example$is_alive == TRUE))\n[1] 48<\/pre>\n\n\n\n<p>As you can see, so far we&#8217;ve obtaining the same number of rows, which is expected for we&#8217;re only using different methods to achieve the same result: Obtaining the number of patients that are alive. Instead of looking for the ones alive, we could also look for the ones that are neither dead or unknown and then subset the opposite. The code follows below:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">> nrow(var_example[-c(which(var_example$is_alive == FALSE | var_example$is_alive == NA)), ])\n[1] 56<\/pre>\n\n\n\n<p>Wait! Something weird happened here. It may surprise you if you&#8217;re not used to deal with NA values in R. The code below may make it clear to you why the code above returned us an unexpected result:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">> TRUE == NA\n[1] NA\n> FALSE == NA\n[1] NA\n> NA == NA\n[1] NA<\/pre>\n\n\n\n<p>As you can see, NA does not work according to what we would expect by looking at it as a logic value. In order to check if something is NA, one must use the <em>is.na function<\/em>.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">> is.na(TRUE)\n[1] FALSE\n> is.na(FALSE)\n[1] FALSE\n> is.na(NA)\nTRUE<\/pre>\n\n\n\n<p>Therefore, the right <em>which function<\/em> usage should be:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">> nrow(var_example[-c(which(var_example$is_alive == FALSE | is.na(var_example$is_alive))), ])\n[1] 48<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">(3) dplyr filter<\/h3>\n\n\n\n<p>Even though it is not part of the R base, the dplyr library is very famous among data scientists. <\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">> library(dplyr)&lt;br>\n> nrow(filter(var_example, is_alive == TRUE))\n[1] 48<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">(4) Plain brackets<\/h3>\n\n\n\n<p>Or we can use plain brackets, without calling any function.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">> nrow(var_example[var_example$is_alive == TRUE,])\n[1] 56<\/pre>\n\n\n\n<p>Wait! We should not have received a different value, should we? We&#8217;re not even playing with NA values, like the example a bit above. What is going on in here?<br><br>Even though some people may assume subset and subsetting by brackets do the same thing, they actually do not. The <em>subset&nbsp;function<\/em> is actually the equivalent to: <\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">> var_example[!is.na(is_alive) &amp; is_alive, ]<\/pre>\n\n\n\n<p>That is, it treats the NA values as FALSE, therefore returning the values we expect, that is, only TRUE values. If we did not have NA values, things would work out closer to what we expect but, unfortunately, NA values are a daily thing in the life of data scientists. The plain brackets, therefore, do not treat NA values as FALSE and will return them. We can verify the NA values are being summed up with the code below:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">> sum(is.na(var_example$is_alive))\n[1] 8\n> sum(is.na(var_example$is_alive)) + nrow(subset(var_example, is_alive == TRUE))\n[1] 56<\/pre>\n\n\n\n<p>Not being aware of it can be a burden, since it is a silent mistake. Sometimes, you may only notice something went wrong after you&#8217;re already analyzing your final results. It may seem silly to fall for this if you have a data frame with 100 rows and 10 columns, for it is easy to know your data by heart (or simply looking at it with <em>View()<\/em>). But what if you have 300.000 rows with 200 columns? It gets more complicated.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Randomly subsetting<\/h3>\n\n\n\n<p>As a gift for the ones that remained until the end of this post, this section is a gift :-). Sometimes, you do not want to subset your data frame according to some value in specific. Instead, you want to sample it for some reason. Take N rows out of N+X. Let&#8217;s say we would like to take 50 rows from our 100 rows, without repeating rows:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">> new_variable &lt;- var_example[sample(1:nrow(var_example), 50,\n   replace=FALSE),]<\/pre>\n\n\n\n<p>And that&#8217;s it folks. I hope you enjoyed today&#8217;s lesson \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p><span class=\"span-reading-time rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\"><b>Reading time: <\/span> <span class=\"rt-time\"> 3<\/span> <span class=\"rt-label rt-postfix\">minutes<\/b><\/span><\/span>The silent [and maybe mortal?] trap in bracket subsetting. Dear reader, It should be clear to you that, as several other programming languages, R provides different ways to tackle the same problem. One common problem in data analysis is to subset your data frame and, as Google can show you, there are several blog posts &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[24],"tags":[11,25],"class_list":["post-229","post","type-post","status-publish","format-standard","hentry","category-r","tag-datascience","tag-r"],"jetpack_publicize_connections":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>The unintended trap in bracket subsetting in R - The Dataist Storyteller<\/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:\/\/mribeirodantas.xyz\/blog\/index.php\/2019\/02\/10\/the-unintended-trap-of-brackets-subsetting-in-r\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"The unintended trap in bracket subsetting in R - The Dataist Storyteller\" \/>\n<meta property=\"og:description\" content=\"Reading time:  3 minutesThe silent [and maybe mortal?] trap in bracket subsetting. Dear reader, It should be clear to you that, as several other programming languages, R provides different ways to tackle the same problem. One common problem in data analysis is to subset your data frame and, as Google can show you, there are several blog posts ...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/mribeirodantas.xyz\/blog\/index.php\/2019\/02\/10\/the-unintended-trap-of-brackets-subsetting-in-r\/\" \/>\n<meta property=\"og:site_name\" content=\"The Dataist Storyteller\" \/>\n<meta property=\"article:published_time\" content=\"2019-02-10T03:53:54+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-02-25T16:45:46+00:00\" \/>\n<meta name=\"author\" content=\"mribeirodantas\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"mribeirodantas\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/mribeirodantas.xyz\/blog\/index.php\/2019\/02\/10\/the-unintended-trap-of-brackets-subsetting-in-r\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/mribeirodantas.xyz\/blog\/index.php\/2019\/02\/10\/the-unintended-trap-of-brackets-subsetting-in-r\/\"},\"author\":{\"name\":\"mribeirodantas\",\"@id\":\"https:\/\/mribeirodantas.xyz\/blog\/#\/schema\/person\/2856ebf8edffabf1f4bbca59bade5957\"},\"headline\":\"The unintended trap in bracket subsetting in R\",\"datePublished\":\"2019-02-10T03:53:54+00:00\",\"dateModified\":\"2019-02-25T16:45:46+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/mribeirodantas.xyz\/blog\/index.php\/2019\/02\/10\/the-unintended-trap-of-brackets-subsetting-in-r\/\"},\"wordCount\":699,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/mribeirodantas.xyz\/blog\/#\/schema\/person\/2856ebf8edffabf1f4bbca59bade5957\"},\"keywords\":[\"datascience\",\"r\"],\"articleSection\":[\"R\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/mribeirodantas.xyz\/blog\/index.php\/2019\/02\/10\/the-unintended-trap-of-brackets-subsetting-in-r\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/mribeirodantas.xyz\/blog\/index.php\/2019\/02\/10\/the-unintended-trap-of-brackets-subsetting-in-r\/\",\"url\":\"https:\/\/mribeirodantas.xyz\/blog\/index.php\/2019\/02\/10\/the-unintended-trap-of-brackets-subsetting-in-r\/\",\"name\":\"The unintended trap in bracket subsetting in R - The Dataist Storyteller\",\"isPartOf\":{\"@id\":\"https:\/\/mribeirodantas.xyz\/blog\/#website\"},\"datePublished\":\"2019-02-10T03:53:54+00:00\",\"dateModified\":\"2019-02-25T16:45:46+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/mribeirodantas.xyz\/blog\/index.php\/2019\/02\/10\/the-unintended-trap-of-brackets-subsetting-in-r\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/mribeirodantas.xyz\/blog\/index.php\/2019\/02\/10\/the-unintended-trap-of-brackets-subsetting-in-r\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/mribeirodantas.xyz\/blog\/index.php\/2019\/02\/10\/the-unintended-trap-of-brackets-subsetting-in-r\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/mribeirodantas.xyz\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"The unintended trap in bracket subsetting in R\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/mribeirodantas.xyz\/blog\/#website\",\"url\":\"https:\/\/mribeirodantas.xyz\/blog\/\",\"name\":\"The Dataist Storyteller\",\"description\":\"Telling stories backed by data\",\"publisher\":{\"@id\":\"https:\/\/mribeirodantas.xyz\/blog\/#\/schema\/person\/2856ebf8edffabf1f4bbca59bade5957\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/mribeirodantas.xyz\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/mribeirodantas.xyz\/blog\/#\/schema\/person\/2856ebf8edffabf1f4bbca59bade5957\",\"name\":\"mribeirodantas\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/mribeirodantas.xyz\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/6687720529e55feab1680cbd98da5c7f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/6687720529e55feab1680cbd98da5c7f?s=96&d=mm&r=g\",\"caption\":\"mribeirodantas\"},\"logo\":{\"@id\":\"https:\/\/mribeirodantas.xyz\/blog\/#\/schema\/person\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"The unintended trap in bracket subsetting in R - The Dataist Storyteller","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:\/\/mribeirodantas.xyz\/blog\/index.php\/2019\/02\/10\/the-unintended-trap-of-brackets-subsetting-in-r\/","og_locale":"en_US","og_type":"article","og_title":"The unintended trap in bracket subsetting in R - The Dataist Storyteller","og_description":"Reading time:  3 minutesThe silent [and maybe mortal?] trap in bracket subsetting. Dear reader, It should be clear to you that, as several other programming languages, R provides different ways to tackle the same problem. One common problem in data analysis is to subset your data frame and, as Google can show you, there are several blog posts ...","og_url":"https:\/\/mribeirodantas.xyz\/blog\/index.php\/2019\/02\/10\/the-unintended-trap-of-brackets-subsetting-in-r\/","og_site_name":"The Dataist Storyteller","article_published_time":"2019-02-10T03:53:54+00:00","article_modified_time":"2019-02-25T16:45:46+00:00","author":"mribeirodantas","twitter_card":"summary_large_image","twitter_misc":{"Written by":"mribeirodantas","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/mribeirodantas.xyz\/blog\/index.php\/2019\/02\/10\/the-unintended-trap-of-brackets-subsetting-in-r\/#article","isPartOf":{"@id":"https:\/\/mribeirodantas.xyz\/blog\/index.php\/2019\/02\/10\/the-unintended-trap-of-brackets-subsetting-in-r\/"},"author":{"name":"mribeirodantas","@id":"https:\/\/mribeirodantas.xyz\/blog\/#\/schema\/person\/2856ebf8edffabf1f4bbca59bade5957"},"headline":"The unintended trap in bracket subsetting in R","datePublished":"2019-02-10T03:53:54+00:00","dateModified":"2019-02-25T16:45:46+00:00","mainEntityOfPage":{"@id":"https:\/\/mribeirodantas.xyz\/blog\/index.php\/2019\/02\/10\/the-unintended-trap-of-brackets-subsetting-in-r\/"},"wordCount":699,"commentCount":0,"publisher":{"@id":"https:\/\/mribeirodantas.xyz\/blog\/#\/schema\/person\/2856ebf8edffabf1f4bbca59bade5957"},"keywords":["datascience","r"],"articleSection":["R"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/mribeirodantas.xyz\/blog\/index.php\/2019\/02\/10\/the-unintended-trap-of-brackets-subsetting-in-r\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/mribeirodantas.xyz\/blog\/index.php\/2019\/02\/10\/the-unintended-trap-of-brackets-subsetting-in-r\/","url":"https:\/\/mribeirodantas.xyz\/blog\/index.php\/2019\/02\/10\/the-unintended-trap-of-brackets-subsetting-in-r\/","name":"The unintended trap in bracket subsetting in R - The Dataist Storyteller","isPartOf":{"@id":"https:\/\/mribeirodantas.xyz\/blog\/#website"},"datePublished":"2019-02-10T03:53:54+00:00","dateModified":"2019-02-25T16:45:46+00:00","breadcrumb":{"@id":"https:\/\/mribeirodantas.xyz\/blog\/index.php\/2019\/02\/10\/the-unintended-trap-of-brackets-subsetting-in-r\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/mribeirodantas.xyz\/blog\/index.php\/2019\/02\/10\/the-unintended-trap-of-brackets-subsetting-in-r\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/mribeirodantas.xyz\/blog\/index.php\/2019\/02\/10\/the-unintended-trap-of-brackets-subsetting-in-r\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/mribeirodantas.xyz\/blog\/"},{"@type":"ListItem","position":2,"name":"The unintended trap in bracket subsetting in R"}]},{"@type":"WebSite","@id":"https:\/\/mribeirodantas.xyz\/blog\/#website","url":"https:\/\/mribeirodantas.xyz\/blog\/","name":"The Dataist Storyteller","description":"Telling stories backed by data","publisher":{"@id":"https:\/\/mribeirodantas.xyz\/blog\/#\/schema\/person\/2856ebf8edffabf1f4bbca59bade5957"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/mribeirodantas.xyz\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/mribeirodantas.xyz\/blog\/#\/schema\/person\/2856ebf8edffabf1f4bbca59bade5957","name":"mribeirodantas","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/mribeirodantas.xyz\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/6687720529e55feab1680cbd98da5c7f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6687720529e55feab1680cbd98da5c7f?s=96&d=mm&r=g","caption":"mribeirodantas"},"logo":{"@id":"https:\/\/mribeirodantas.xyz\/blog\/#\/schema\/person\/image\/"}}]}},"jetpack_featured_media_url":"","uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"mribeirodantas","author_link":"https:\/\/mribeirodantas.xyz\/blog\/index.php\/author\/mribeirodantas\/"},"uagb_comment_info":23,"uagb_excerpt":"Reading time: 3 minutesThe silent [and maybe mortal?] trap in bracket subsetting. Dear reader, It should be clear to you that, as several other programming languages, R provides different ways to tackle the same problem. One common problem in data analysis is to subset your data frame and, as Google can show you, there are&hellip;","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/paw9jx-3H","jetpack-related-posts":[],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/mribeirodantas.xyz\/blog\/index.php\/wp-json\/wp\/v2\/posts\/229","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mribeirodantas.xyz\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mribeirodantas.xyz\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mribeirodantas.xyz\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mribeirodantas.xyz\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=229"}],"version-history":[{"count":29,"href":"https:\/\/mribeirodantas.xyz\/blog\/index.php\/wp-json\/wp\/v2\/posts\/229\/revisions"}],"predecessor-version":[{"id":343,"href":"https:\/\/mribeirodantas.xyz\/blog\/index.php\/wp-json\/wp\/v2\/posts\/229\/revisions\/343"}],"wp:attachment":[{"href":"https:\/\/mribeirodantas.xyz\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=229"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mribeirodantas.xyz\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=229"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mribeirodantas.xyz\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=229"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}