{"id":192511,"date":"2023-06-27T10:36:26","date_gmt":"2023-06-27T14:36:26","guid":{"rendered":"https:\/\/ibkrcampus.com\/?p=192511"},"modified":"2023-06-27T10:36:26","modified_gmt":"2023-06-27T14:36:26","slug":"those-other-apply-functions","status":"publish","type":"post","link":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/those-other-apply-functions\/","title":{"rendered":"Those &#8220;Other&#8221; Apply Functions&#8230;"},"content":{"rendered":"\n<p>So you know&nbsp;<a href=\"https:\/\/www.r-bloggers.com\/using-apply-sapply-lapply-in-r\/\">lapply, sapply, and apply<\/a>\u2026but\u2026what about&nbsp;<em>rapply<\/em>,&nbsp;<em>vapply<\/em>, or&nbsp;<em>eapply<\/em>? These are generally a little less known as far as the apply family of functions in R go, so this post will explore how they work.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-rapply\"><strong>rapply<\/strong><\/h2>\n\n\n\n<p>Let\u2019s start with&nbsp;<em>rapply<\/em>. This function has a couple of different purposes. One is to recursively apply a function to a list. We\u2019ll get to that in a moment. The other use of&nbsp;<em>rapply<\/em>&nbsp;is to a apply a function to only those elements in a list (or columns in a data frame) that belong to a specified class. For example, let\u2019s say we have a data frame with a mix of categorical and numeric variables, but we want to evaluate a function&nbsp;<em>only<\/em>&nbsp;on the numeric variables.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-use-rapply-to-apply-a-function-to-elements-of-a-given-class\"><strong>Use rapply to apply a function to elements of a given class<\/strong><\/h4>\n\n\n\n<p>Using the traditional iris dataset, we can run the one-liner below to get the mean of each numeric column. This works almost exactly like&nbsp;<em>sapply<\/em>, except we add an extra parameter,&nbsp;<em>class<\/em>, to specify we only want to apply our function to the numeric columns in iris.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># apply to only numeric variables\nrapply(iris, mean, class = \"numeric\")\n \nrapply(iris, max, class = \"numeric\")\n \nrapply(iris, min, class = \"numeric\")\n \n# or apply to only factor columns\nrapply(iris, summary, class = \"factor\")<\/pre>\n\n\n\n<p>If you\u2019re unsure of the class of a particular column in a data frame,&nbsp;<em>df<\/em>, just run the following to get the clases of each variable.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sapply(df, class)<\/pre>\n\n\n\n<p>The other purpose of&nbsp;<em>rapply<\/em>&nbsp;is to apply a function recursively to a list.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">temp &lt;- list(a = c(1, 2, 3), \n             b = list(a = c(4, 5, 6), b = c(7, 8, 9)),\n             c = list(a = c(10, 11, 12), b = c(13, 14, 15)))\n \n \nrapply(temp, sum)<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"752\" height=\"423\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2023\/06\/r-other-apply-functions-theautomatic-net-1-1.png\" alt=\"\" class=\"wp-image-192518 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/06\/r-other-apply-functions-theautomatic-net-1-1.png 752w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/06\/r-other-apply-functions-theautomatic-net-1-1-700x394.png 700w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/06\/r-other-apply-functions-theautomatic-net-1-1-300x169.png 300w\" data-sizes=\"(max-width: 752px) 100vw, 752px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 752px; aspect-ratio: 752\/423;\" \/><\/figure>\n\n\n\n<p>Running&nbsp;<em>rapply<\/em>&nbsp;here will recursively sum the elements of each vector in each list and sub-list of&nbsp;<em>temp<\/em>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"764\" height=\"101\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2023\/06\/r-other-apply-functions-theautomatic-net-2-1.png\" alt=\"\" class=\"wp-image-192520 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/06\/r-other-apply-functions-theautomatic-net-2-1.png 764w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/06\/r-other-apply-functions-theautomatic-net-2-1-700x93.png 700w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/06\/r-other-apply-functions-theautomatic-net-2-1-300x40.png 300w\" data-sizes=\"(max-width: 764px) 100vw, 764px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 764px; aspect-ratio: 764\/101;\" \/><\/figure>\n\n\n\n<p><em>rapply<\/em>, similar to&nbsp;<em>sapply<\/em>, has an optional parameter&nbsp;<em>how<\/em>, which specifies how the output should be returned. So in the above example, if we wanted the output to be returned as a list instead of a vector, we could do this:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">rapply(temp, sum, how = \"list\")<\/pre>\n\n\n\n<p>Also, if our nested list contained mixed data types, we could specify applying a function to only a specific type:<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>vapply<\/strong><\/h2>\n\n\n\n<p><em>vapply<\/em>&nbsp;works similarly to&nbsp;<em>sapply<\/em>, except that it requires an extra parameter specifying the type of the expected return value. This extra parameter is useful in coding because it can help ensure silent errors don\u2019t cause issues for you.<\/p>\n\n\n\n<p>For example, suppose we have the following list of mixed data types:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sample_list &lt;- list(10, 20, 30, \"some_string\")<\/pre>\n\n\n\n<p>Now if we run the below code with&nbsp;<em>sapply<\/em>, we get a vector of characters, which is not exactly what we want. For instance, if we didn\u2019t know our list had mixed data types, and we ran our function to the get the max of each element in the list, then R doesn\u2019t return an error here. Instead, it silently converts the output to a character vector.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sapply(sample_list, max)<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"768\" height=\"67\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2023\/06\/r-other-apply-functions-theautomatic-net-3.png\" alt=\"\" class=\"wp-image-192522 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/06\/r-other-apply-functions-theautomatic-net-3.png 768w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/06\/r-other-apply-functions-theautomatic-net-3-700x61.png 700w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/06\/r-other-apply-functions-theautomatic-net-3-300x26.png 300w\" data-sizes=\"(max-width: 768px) 100vw, 768px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 768px; aspect-ratio: 768\/67;\" \/><\/figure>\n\n\n\n<p>However, we can catch this error using&nbsp;<em>vapply<\/em>.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">vapply(sample_list, max, numeric(1))<\/pre>\n\n\n\n<p>This third parameter,&nbsp;<em>numeric(1)<\/em>&nbsp;specifies that we want the output returned by&nbsp;<em>vapply<\/em>&nbsp;to be numeric. This means if an issue occurs in returning a numeric result,&nbsp;<em>vapply<\/em>&nbsp;will result in an error, rather than trying to coerce the result to a different data type. This could allow you to investigate why a character is in the list, for example.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"772\" height=\"108\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2023\/06\/r-other-apply-functions-theautomatic-net-4.png\" alt=\"\" class=\"wp-image-192523 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/06\/r-other-apply-functions-theautomatic-net-4.png 772w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/06\/r-other-apply-functions-theautomatic-net-4-700x98.png 700w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/06\/r-other-apply-functions-theautomatic-net-4-300x42.png 300w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/06\/r-other-apply-functions-theautomatic-net-4-768x107.png 768w\" data-sizes=\"(max-width: 772px) 100vw, 772px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 772px; aspect-ratio: 772\/108;\" \/><\/figure>\n\n\n\n<p><em>vapply\u2019s<\/em>&nbsp;ability to catch errors based off data types makes it useful for running R code in production&nbsp;<a href=\"https:\/\/theautomatic.net\/2018\/10\/31\/how-to-run-r-from-the-task-scheduler\/\">or as a scheduled task<\/a>&nbsp;as an extra measure to guard against type issues.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>eapply<\/strong><\/h2>\n\n\n\n<p><em>eapply<\/em>&nbsp;applies a function to every named element in an environment. This requires a little knowledge about&nbsp;<a href=\"https:\/\/www.r-bloggers.com\/environments-in-r\/\">how environments work in R<\/a>. It works pretty similarly to&nbsp;<em>lapply<\/em>&nbsp;in that it also returns a list as output. The input to&nbsp;<em>eapply<\/em>, however, must be an environment, whereas&nbsp;<em>lapply<\/em>&nbsp;can take a variety of objects as inputs.<\/p>\n\n\n\n<p>Here\u2019s an example:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># create a new environment\ne &lt;- new.env()\n \ne$a &lt;- 10\ne$b &lt;- 20\ne$c &lt;- 30\n \n# multiply every element in the environment by 2\nnew_e &lt;- eapply(e, function(x) x * 2)<\/pre>\n\n\n\n<p>In the above example, we create a list from the initiated environment,&nbsp;<em>e<\/em>, and then double the value of each element.<\/p>\n\n\n\n<p>Here\u2019s another example, using the environment within a function:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sample_func &lt;- function()\n{\n \n   df1 &lt;- data.frame(a = c(1, 2, 3, 4), b = c(5, 6, 7, 8))\n   df2 &lt;- data.frame(a = c(1, 2, 3, 4, 5), b = c(5, 6, 7, 8, 9))\n   df3 &lt;- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(5, 6, 7, 8, 9, 10)) \n \n   eapply(environment(), nrow)\n \n}\n \nsample_func()<\/pre>\n\n\n\n<p>Above, calling&nbsp;<em>sample_func<\/em>&nbsp;will return a list of the number of rows for each respective data frame defined within the function\u2019s environment:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"746\" height=\"220\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2023\/06\/r-other-apply-functions-theautomatic-net-5.png\" alt=\"\" class=\"wp-image-192525 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/06\/r-other-apply-functions-theautomatic-net-5.png 746w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/06\/r-other-apply-functions-theautomatic-net-5-700x206.png 700w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/06\/r-other-apply-functions-theautomatic-net-5-300x88.png 300w\" data-sizes=\"(max-width: 746px) 100vw, 746px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 746px; aspect-ratio: 746\/220;\" \/><\/figure>\n\n\n\n<p><em>eapply<\/em>&nbsp;can also be called with the parameter&nbsp;<strong>USE.NAMES = FALSE<\/strong>, which will return an unnamed list.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">eapply(environment(), nrow, USE.NAMES = FALSE)<\/pre>\n\n\n\n<p>One other difference versus&nbsp;<em>lapply<\/em>&nbsp;is that&nbsp;<em>eapply<\/em>&nbsp;can take an optional Boolean parameter called&nbsp;<em>all.names<\/em>&nbsp;that specifies if the function input should be applied to just the visible elements of the environment, or to all objects. Here\u2019s an example to illustrate:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">e &lt;- new.env()\ne$.test &lt;- 100\ne$other_test &lt;- 64<\/pre>\n\n\n\n<p>Here, we defined an environment with one object called&nbsp;<em>.test<\/em>&nbsp;and one called&nbsp;<em>other_test<\/em>. Next, if we run this:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">eapply(e, sqrt)<\/pre>\n\n\n\n<p>we\u2019ll get back a list with one element \u2013 8. As in,&nbsp;<em>eapply<\/em>&nbsp;is only applying the&nbsp;<em>sqrt<\/em>&nbsp;function to the object named&nbsp;<em>other_test<\/em>&nbsp;in&nbsp;<em>e<\/em>&nbsp;because it is not a hidden object. Names that begin with a dot (hidden objects) are excluded from the function\u2019s application. To apply the function to every object in the environment, we need to set the parameter&nbsp;<strong>all.names = TRUE<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"776\" height=\"254\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2023\/06\/r-other-apply-functions-theautomatic-net-6.png\" alt=\"\" class=\"wp-image-192526 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/06\/r-other-apply-functions-theautomatic-net-6.png 776w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/06\/r-other-apply-functions-theautomatic-net-6-700x229.png 700w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/06\/r-other-apply-functions-theautomatic-net-6-300x98.png 300w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/06\/r-other-apply-functions-theautomatic-net-6-768x251.png 768w\" data-sizes=\"(max-width: 776px) 100vw, 776px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 776px; aspect-ratio: 776\/254;\" \/><\/figure>\n\n\n\n<p><em>Originally posted on <a href=\"https:\/\/theautomatic.net\/2018\/11\/13\/those-other-apply-functions\/\">TheAutomatic.net<\/a> blog.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Let&#8217;s start with rapply. This function has a couple of different purposes.<\/p>\n","protected":false},"author":388,"featured_media":161338,"comment_status":"open","ping_status":"closed","sticky":true,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[339,343,338,341,342],"tags":[806,15495,487,15493,15494],"contributors-categories":[13695],"class_list":{"0":"post-192511","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-data-science","8":"category-programing-languages","9":"category-ibkr-quant-news","10":"category-quant-development","11":"category-r-development","12":"tag-data-science","13":"tag-eapply-function","14":"tag-r","15":"tag-rapply-function","16":"tag-vapply-function","17":"contributors-categories-theautomatic-net"},"pp_statuses_selecting_workflow":false,"pp_workflow_action":"current","pp_status_selection":"publish","acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.9 (Yoast SEO v27.5) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Those &#8220;Other&#8221; Apply Functions&#8230;<\/title>\n<meta name=\"description\" content=\"Let&#039;s start with rapply. This function has a couple of different purposes.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.interactivebrokers.com\/campus\/wp-json\/wp\/v2\/posts\/192511\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Those &quot;Other&quot; Apply Functions... | IBKR Campus US\" \/>\n<meta property=\"og:description\" content=\"Let&#039;s start with rapply. This function has a couple of different purposes.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/those-other-apply-functions\/\" \/>\n<meta property=\"og:site_name\" content=\"IBKR Campus US\" \/>\n<meta property=\"article:published_time\" content=\"2023-06-27T14:36:26+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/10\/quant-binary-red-green.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1000\" \/>\n\t<meta property=\"og:image:height\" content=\"563\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Andrew Treadway\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Andrew Treadway\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\n\t    \"@context\": \"https:\\\/\\\/schema.org\",\n\t    \"@graph\": [\n\t        {\n\t            \"@type\": \"NewsArticle\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/those-other-apply-functions\\\/#article\",\n\t            \"isPartOf\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/those-other-apply-functions\\\/\"\n\t            },\n\t            \"author\": {\n\t                \"name\": \"Andrew Treadway\",\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/person\\\/d4018570a16fb867f1c08412fc9c64bc\"\n\t            },\n\t            \"headline\": \"Those &#8220;Other&#8221; Apply Functions&#8230;\",\n\t            \"datePublished\": \"2023-06-27T14:36:26+00:00\",\n\t            \"mainEntityOfPage\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/those-other-apply-functions\\\/\"\n\t            },\n\t            \"wordCount\": 870,\n\t            \"commentCount\": 2,\n\t            \"publisher\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/those-other-apply-functions\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2022\\\/10\\\/quant-binary-red-green.jpg\",\n\t            \"keywords\": [\n\t                \"Data Science\",\n\t                \"eapply function\",\n\t                \"R\",\n\t                \"rapply function\",\n\t                \"vapply function\"\n\t            ],\n\t            \"articleSection\": [\n\t                \"Data Science\",\n\t                \"Programming Languages\",\n\t                \"Quant\",\n\t                \"Quant Development\",\n\t                \"R Development\"\n\t            ],\n\t            \"inLanguage\": \"en-US\",\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"CommentAction\",\n\t                    \"name\": \"Comment\",\n\t                    \"target\": [\n\t                        \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/those-other-apply-functions\\\/#respond\"\n\t                    ]\n\t                }\n\t            ]\n\t        },\n\t        {\n\t            \"@type\": \"WebPage\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/those-other-apply-functions\\\/\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/those-other-apply-functions\\\/\",\n\t            \"name\": \"Those \\\"Other\\\" Apply Functions... | IBKR Campus US\",\n\t            \"isPartOf\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#website\"\n\t            },\n\t            \"primaryImageOfPage\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/those-other-apply-functions\\\/#primaryimage\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/those-other-apply-functions\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2022\\\/10\\\/quant-binary-red-green.jpg\",\n\t            \"datePublished\": \"2023-06-27T14:36:26+00:00\",\n\t            \"description\": \"Let's start with rapply. This function has a couple of different purposes.\",\n\t            \"inLanguage\": \"en-US\",\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"ReadAction\",\n\t                    \"target\": [\n\t                        \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/those-other-apply-functions\\\/\"\n\t                    ]\n\t                }\n\t            ]\n\t        },\n\t        {\n\t            \"@type\": \"ImageObject\",\n\t            \"inLanguage\": \"en-US\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/those-other-apply-functions\\\/#primaryimage\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2022\\\/10\\\/quant-binary-red-green.jpg\",\n\t            \"contentUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2022\\\/10\\\/quant-binary-red-green.jpg\",\n\t            \"width\": 1000,\n\t            \"height\": 563,\n\t            \"caption\": \"Quant\"\n\t        },\n\t        {\n\t            \"@type\": \"WebSite\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#website\",\n\t            \"url\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/\",\n\t            \"name\": \"IBKR Campus US\",\n\t            \"description\": \"Financial Education from Interactive Brokers\",\n\t            \"publisher\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\"\n\t            },\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"SearchAction\",\n\t                    \"target\": {\n\t                        \"@type\": \"EntryPoint\",\n\t                        \"urlTemplate\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/?s={search_term_string}\"\n\t                    },\n\t                    \"query-input\": {\n\t                        \"@type\": \"PropertyValueSpecification\",\n\t                        \"valueRequired\": true,\n\t                        \"valueName\": \"search_term_string\"\n\t                    }\n\t                }\n\t            ],\n\t            \"inLanguage\": \"en-US\"\n\t        },\n\t        {\n\t            \"@type\": \"Organization\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\",\n\t            \"name\": \"Interactive Brokers\",\n\t            \"alternateName\": \"IBKR\",\n\t            \"url\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/\",\n\t            \"logo\": {\n\t                \"@type\": \"ImageObject\",\n\t                \"inLanguage\": \"en-US\",\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/logo\\\/image\\\/\",\n\t                \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2024\\\/05\\\/ibkr-campus-logo.jpg\",\n\t                \"contentUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2024\\\/05\\\/ibkr-campus-logo.jpg\",\n\t                \"width\": 669,\n\t                \"height\": 669,\n\t                \"caption\": \"Interactive Brokers\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/logo\\\/image\\\/\"\n\t            },\n\t            \"publishingPrinciples\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/about-ibkr-campus\\\/\",\n\t            \"ethicsPolicy\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/cyber-security-notice\\\/\"\n\t        },\n\t        {\n\t            \"@type\": \"Person\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/person\\\/d4018570a16fb867f1c08412fc9c64bc\",\n\t            \"name\": \"Andrew Treadway\",\n\t            \"description\": \"Andrew Treadway currently works as a Senior Data Scientist, and has experience doing analytics, software automation, and ETL. He completed a master\u2019s degree in computer science \\\/ machine learning, and an undergraduate degree in pure mathematics. Connect with him on LinkedIn: https:\\\/\\\/www.linkedin.com\\\/in\\\/andrew-treadway-a3b19b103\\\/In addition to TheAutomatic.net blog, he also teaches in-person courses on Python and R through my NYC meetup: more details.\",\n\t            \"sameAs\": [\n\t                \"https:\\\/\\\/theautomatic.net\\\/about-me\\\/\"\n\t            ],\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/author\\\/andrewtreadway\\\/\"\n\t        }\n\t    ]\n\t}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Those &#8220;Other&#8221; Apply Functions&#8230;","description":"Let's start with rapply. This function has a couple of different purposes.","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:\/\/www.interactivebrokers.com\/campus\/wp-json\/wp\/v2\/posts\/192511\/","og_locale":"en_US","og_type":"article","og_title":"Those \"Other\" Apply Functions... | IBKR Campus US","og_description":"Let's start with rapply. This function has a couple of different purposes.","og_url":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/those-other-apply-functions\/","og_site_name":"IBKR Campus US","article_published_time":"2023-06-27T14:36:26+00:00","og_image":[{"width":1000,"height":563,"url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/10\/quant-binary-red-green.jpg","type":"image\/jpeg"}],"author":"Andrew Treadway","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Andrew Treadway","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"NewsArticle","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/those-other-apply-functions\/#article","isPartOf":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/those-other-apply-functions\/"},"author":{"name":"Andrew Treadway","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/person\/d4018570a16fb867f1c08412fc9c64bc"},"headline":"Those &#8220;Other&#8221; Apply Functions&#8230;","datePublished":"2023-06-27T14:36:26+00:00","mainEntityOfPage":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/those-other-apply-functions\/"},"wordCount":870,"commentCount":2,"publisher":{"@id":"https:\/\/ibkrcampus.com\/campus\/#organization"},"image":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/those-other-apply-functions\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/10\/quant-binary-red-green.jpg","keywords":["Data Science","eapply function","R","rapply function","vapply function"],"articleSection":["Data Science","Programming Languages","Quant","Quant Development","R Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/those-other-apply-functions\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/those-other-apply-functions\/","url":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/those-other-apply-functions\/","name":"Those \"Other\" Apply Functions... | IBKR Campus US","isPartOf":{"@id":"https:\/\/ibkrcampus.com\/campus\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/those-other-apply-functions\/#primaryimage"},"image":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/those-other-apply-functions\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/10\/quant-binary-red-green.jpg","datePublished":"2023-06-27T14:36:26+00:00","description":"Let's start with rapply. This function has a couple of different purposes.","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/those-other-apply-functions\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/those-other-apply-functions\/#primaryimage","url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/10\/quant-binary-red-green.jpg","contentUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/10\/quant-binary-red-green.jpg","width":1000,"height":563,"caption":"Quant"},{"@type":"WebSite","@id":"https:\/\/ibkrcampus.com\/campus\/#website","url":"https:\/\/ibkrcampus.com\/campus\/","name":"IBKR Campus US","description":"Financial Education from Interactive Brokers","publisher":{"@id":"https:\/\/ibkrcampus.com\/campus\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ibkrcampus.com\/campus\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/ibkrcampus.com\/campus\/#organization","name":"Interactive Brokers","alternateName":"IBKR","url":"https:\/\/ibkrcampus.com\/campus\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/logo\/image\/","url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/05\/ibkr-campus-logo.jpg","contentUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/05\/ibkr-campus-logo.jpg","width":669,"height":669,"caption":"Interactive Brokers"},"image":{"@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/logo\/image\/"},"publishingPrinciples":"https:\/\/www.interactivebrokers.com\/campus\/about-ibkr-campus\/","ethicsPolicy":"https:\/\/www.interactivebrokers.com\/campus\/cyber-security-notice\/"},{"@type":"Person","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/person\/d4018570a16fb867f1c08412fc9c64bc","name":"Andrew Treadway","description":"Andrew Treadway currently works as a Senior Data Scientist, and has experience doing analytics, software automation, and ETL. He completed a master\u2019s degree in computer science \/ machine learning, and an undergraduate degree in pure mathematics. Connect with him on LinkedIn: https:\/\/www.linkedin.com\/in\/andrew-treadway-a3b19b103\/In addition to TheAutomatic.net blog, he also teaches in-person courses on Python and R through my NYC meetup: more details.","sameAs":["https:\/\/theautomatic.net\/about-me\/"],"url":"https:\/\/www.interactivebrokers.com\/campus\/author\/andrewtreadway\/"}]}},"jetpack_featured_media_url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/10\/quant-binary-red-green.jpg","_links":{"self":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts\/192511","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/users\/388"}],"replies":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/comments?post=192511"}],"version-history":[{"count":0,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts\/192511\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media\/161338"}],"wp:attachment":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media?parent=192511"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/categories?post=192511"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/tags?post=192511"},{"taxonomy":"contributors-categories","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/contributors-categories?post=192511"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}