

{"id":2786,"date":"2017-06-09T11:26:19","date_gmt":"2017-06-09T11:26:19","guid":{"rendered":"http:\/\/data-flair.training\/blogs\/?p=2786"},"modified":"2021-08-25T18:21:00","modified_gmt":"2021-08-25T12:51:00","slug":"r-arguments-introduction","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/r-arguments-introduction\/","title":{"rendered":"Arguments in R Programming Language &#8211; Get a Deep Insight!"},"content":{"rendered":"<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:1467,&quot;href&quot;:&quot;https:\\\/\\\/en.wikipedia.org\\\/wiki\\\/R_(programming_language)&quot;,&quot;archived_href&quot;:&quot;http:\\\/\\\/web-wp.archive.org\\\/web\\\/20251001042859\\\/https:\\\/\\\/en.wikipedia.org\\\/wiki\\\/R_(programming_language)&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2025-12-09 08:17:04&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-12 12:22:33&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-15 12:29:21&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-18 15:20:53&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-21 18:00:25&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-25 04:08:57&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-28 06:54:42&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-31 09:47:17&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-03 17:14:22&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-06 19:17:34&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-09 21:09:32&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-13 04:31:41&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-16 15:06:53&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-19 19:03:58&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-23 05:30:29&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-26 10:18:28&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-29 11:45:43&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-01 12:00:34&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-04 12:09:55&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-07 15:09:43&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-10 18:01:34&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-13 23:45:59&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-17 05:29:44&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-20 07:23:59&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-23 10:05:24&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-26 14:54:33&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-01 16:00:29&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-04 19:56:49&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-08 03:19:57&quot;,&quot;http_code&quot;:429},{&quot;date&quot;:&quot;2026-03-11 07:47:37&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-14 13:54:22&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-17 17:24:09&quot;,&quot;http_code&quot;:429},{&quot;date&quot;:&quot;2026-03-20 23:04:55&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-24 00:07:34&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-27 00:15:51&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-30 08:20:38&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-03 14:48:26&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-06 19:55:35&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-10 05:52:27&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-13 07:47:26&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-16 08:05:10&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-19 13:04:23&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-22 13:52:44&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-25 13:58:03&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-29 01:16:25&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-02 04:13:02&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-05 06:33:38&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-08 17:48:43&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-12 03:38:06&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-15 04:53:06&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-18 09:15:30&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-21 12:35:48&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-25 03:51:04&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-28 07:13:15&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-01 04:45:49&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-06-04 06:40:14&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-07 06:45:43&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-06-10 09:02:48&quot;,&quot;http_code&quot;:404}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-06-10 09:02:48&quot;,&quot;http_code&quot;:404},&quot;process&quot;:&quot;done&quot;}]'><\/div>\n<p>With this tutorial, you will get a complete understanding of R function arguments. Firstly, we will discuss about the arguments in R language and process to add more arguments in R. You will also learn to add a mult argument and default value in R and usage of dots argument, function as an argument and anonymous functions in R.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Arguments-in-R-1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-63447\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Arguments-in-R-1.jpg\" alt=\"Arguments in R Programming\" width=\"802\" height=\"420\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Arguments-in-R-1.jpg 802w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Arguments-in-R-1-150x79.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Arguments-in-R-1-300x157.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Arguments-in-R-1-768x402.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Arguments-in-R-1-520x272.jpg 520w\" sizes=\"auto, (max-width: 802px) 100vw, 802px\" \/><\/a><\/p>\n<h2>Arguments in R Programming Language<\/h2>\n<p><em>Arguments are always named when you define a function.<\/em> When you call a function, you do not have to specify the name of the argument. Arguments are optional; you do not have to specify a value for them. They can have a default value, which is used if you do not specify a value for that argument yourself. You can use as many arguments as you like, there is no limit to the number of arguments. An argument list comprises of comma-separated values that contain the various formal arguments.<\/p>\n<p><em><strong>Before moving further, you must check the <a href=\"https:\/\/data-flair.training\/blogs\/r-recursive-function\/\">R Recursive Function Tutorial<\/a><\/strong><\/em><\/p>\n<h3>Adding More Arguments in R<\/h3>\n<p>To pass values to a function, you can use R arguments as many as needed.\u00a0First, we will create our generic function addPercent as follows:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">addPercent &lt;- function(x, mult = 100, ...){\r\n\u00a0percent &lt;- round(x*mult, ...)\r\n\u00a0paste(percent, \"%\", sep = \"\")\r\n}<\/pre>\n<p>The<em> addPercent<\/em>\u00a0function converts the value to a percentage. When the calculated numbers are in percentage format, then first you will have to divide these numbers by 100 to get the correct result.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;\u00a0percentages\u00a0&lt;-\u00a0c(58.23,\u00a0120.4,\u00a033)\r\n&gt;\u00a0addPercent(percentages\/100)<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Adding-More-Arguments-in-R.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-58808\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Adding-More-Arguments-in-R.jpg\" alt=\"Adding More Arguments in R\" width=\"1366\" height=\"728\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Adding-More-Arguments-in-R.jpg 1366w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Adding-More-Arguments-in-R-150x80.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Adding-More-Arguments-in-R-300x160.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Adding-More-Arguments-in-R-768x409.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Adding-More-Arguments-in-R-1024x546.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Adding-More-Arguments-in-R-520x277.jpg 520w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/a><\/p>\n<p>This is how more arguments can be added to a function.<\/p>\n<p>That is quite a way around, but you can avoid this by adding another argument to the function that controls the multiplication factor.<\/p>\n<p><em><strong>Don&#8217;t forget to explore the <a href=\"https:\/\/data-flair.training\/blogs\/r-numeric-and-character-functions\/\">Numeric and Character Functions in R<\/a><\/strong><\/em><\/p>\n<h3>Adding the mult Argument in R<\/h3>\n<p>Now, we know that to add extra arguments, we need to include them between the parentheses after the function keyword. We separate the arguments with a comma.\u00a0Let&#8217;s discuss it with an example:<\/p>\n<p>The code to add the mult argument is shown below:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">addPercent &lt;- function(x, mult ){\r\n\u00a0percent &lt;- round(x*mult, \u00a0digits = 1\r\n\u00a0paste(percent, \"%\", sep = \"\"\r\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<h3><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Adding-mult-argument-in-R.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-58809\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Adding-mult-argument-in-R.jpg\" alt=\"Adding mult argument in R\" width=\"1366\" height=\"728\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Adding-mult-argument-in-R.jpg 1366w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Adding-mult-argument-in-R-150x80.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Adding-mult-argument-in-R-300x160.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Adding-mult-argument-in-R-768x409.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Adding-mult-argument-in-R-1024x546.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Adding-mult-argument-in-R-520x277.jpg 520w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/a><\/h3>\n<h3>Adding a Default Value in R<\/h3>\n<p>Specifying a default value for an argument helps you drop the task of specifying a value every time you make a call to the function.<\/p>\n<p>Adding an extra argument gives you more control over what the function does, but it also introduces a new problem &#8211; If you do not specify the <em>mult<\/em> argument in the <em>addPercent<\/em> function, it will give an error as \u201c<em>mult is missing<\/em>\u201d.<\/p>\n<p>R has no way of knowing which number you want to multiply by x, so it stops and tells you that it needs more information.<\/p>\n<p>You can specify default values for any disagreements in the argument list by adding the = sign and default value after the respective argument.<\/p>\n<p>You can specify a default value for argument mult to avoid specifying mult=100 every time.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">addPercent &lt;- function(x, mult = 100){\r\npercent &lt;- round(x * mult, digits = 1)\r\npaste(percent, \u201c%\u201d, sep = \u201c\u201d)\r\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Adding-default-value-in-R.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-58810\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Adding-default-value-in-R.jpg\" alt=\"Adding default value in R\" width=\"1366\" height=\"629\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Adding-default-value-in-R.jpg 1366w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Adding-default-value-in-R-150x69.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Adding-default-value-in-R-300x138.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Adding-default-value-in-R-768x354.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Adding-default-value-in-R-1024x472.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Adding-default-value-in-R-980x450.jpg 980w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Adding-default-value-in-R-520x239.jpg 520w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/a><\/p>\n<p><em><strong>Wait! Do you know about <a href=\"https:\/\/data-flair.training\/blogs\/r-packages-tutorial\/\">R Packages<\/a><\/strong><\/em><\/p>\n<h3>Using the Dots Argument in R<\/h3>\n<p>The special type of argument <strong>\u2018&#8230;\u2019<\/strong> can contain any number of supplied arguments. It is used for a variety of purposes and allows you to write a\u00a0function that takes an arbitrary number of arguments.<\/p>\n<p>If you have several arguments and you pass them to other functions inside the body, you will end up with a long list of arguments. Therefore, rather than this, you can use the\u00a0dots argument.<\/p>\n<p><em>You use the dots argument by adding it at the end of the argument list of your own function, and at the end of the arguments for the function, you want to pass the arguments to.<\/em><\/p>\n<p>Let us see how we can use dots argument in <a href=\"https:\/\/en.wikipedia.org\/wiki\/R_(programming_language)\">R<\/a>:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">addPercent &lt;- function(x, mult = 100, ...){\u00a0\u00a0\r\npercent &lt;- round(x * mult, ...)\r\npaste(percent, \u201c%\u201d, sep = \u201c\u201d)\r\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Using-Dots-Argument-in-R.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-58811\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Using-Dots-Argument-in-R.jpg\" alt=\"Using Dots Argument in R\" width=\"1366\" height=\"629\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Using-Dots-Argument-in-R.jpg 1366w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Using-Dots-Argument-in-R-150x69.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Using-Dots-Argument-in-R-300x138.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Using-Dots-Argument-in-R-768x354.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Using-Dots-Argument-in-R-1024x472.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Using-Dots-Argument-in-R-980x450.jpg 980w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Using-Dots-Argument-in-R-520x239.jpg 520w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/a><\/p>\n<p>R allows you to use the dots argument in more than one function within the body. But, before passing arguments to more than one function in the body, you have to be sure that this will not cause any trouble. R passes the extra arguments to each function and complains about the resulting mess afterwards.<\/p>\n<h3>Using Functions as Arguments<\/h3>\n<p>In R, you can pass a function as an argument. You can also pass function code to an argument.<\/p>\n<p>Then, you can assign the complete code of a function to a new object.<\/p>\n<p>In the above example of rounding the value, you can pass the <em>round()<\/em> function as an argument to <em>addPercent()<\/em> function as below:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">addPercent &lt;- function(x, mult = 100, FUN = round, ...){\u00a0 \u00a0 \u00a0\u00a0\r\npercent &lt;- FUN(x * mult, ...)\u00a0 \u00a0\u00a0\r\npaste(percent, \u201c%\u201d, sep = \u201c\u201d)\r\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Using-Functions-as-Arguments.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-58812\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Using-Functions-as-Arguments.jpg\" alt=\"Using Functions as Arguments\" width=\"1366\" height=\"629\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Using-Functions-as-Arguments.jpg 1366w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Using-Functions-as-Arguments-150x69.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Using-Functions-as-Arguments-300x138.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Using-Functions-as-Arguments-768x354.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Using-Functions-as-Arguments-1024x472.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Using-Functions-as-Arguments-980x450.jpg 980w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Using-Functions-as-Arguments-520x239.jpg 520w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/a><\/p>\n<p><em><strong>Spare some time to check &#8211;<a href=\"https:\/\/data-flair.training\/blogs\/r-vector-functions\/\"> List of R Vector Functions<\/a><\/strong><\/em><\/p>\n<h3>Using Anonymous Functions in R<\/h3>\n<p><em>Any function which does not have a name is called an anonymous function.<\/em> They can be used for 1 liner code. You can add code as an argument in the <em>anonymous function<\/em>.<\/p>\n<p>In the preceding example, you can use any function you want for the FUN argument. In fact, that function does not even need to have a name, because you copy the code as it is. So, instead of giving a function name, you can add the code as an argument in the form of a nameless or anonymous function.<\/p>\n<p>Let us see this with an example:<\/p>\n<p>Suppose, you have the quarterly profits of your company in a vector as follows:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; profits &lt;- c(2100, 1430, 3580, 5230)<\/pre>\n<p>And, you want to report how much profit was made in each quarter relative to the total for the year. For this, you will have to use your new <em>addPercent()<\/em> function. To calculate the relative profits, you could write a <em>rel.profit()<\/em> function as follows:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;rel.profit &lt;- function(x) round(x \/ sum(x) * 100)<\/pre>\n<p>Instead of using the function name, you can use the function body itself as an argument.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; addPercent(profits,FUN = function(x) round(x \/ sum(x) * 100))<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Using-Anonymous-Functions-in-R.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-58813\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Using-Anonymous-Functions-in-R.jpg\" alt=\"Using Anonymous Functions in R\" width=\"1366\" height=\"629\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Using-Anonymous-Functions-in-R.jpg 1366w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Using-Anonymous-Functions-in-R-150x69.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Using-Anonymous-Functions-in-R-300x138.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Using-Anonymous-Functions-in-R-768x354.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Using-Anonymous-Functions-in-R-1024x472.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Using-Anonymous-Functions-in-R-980x450.jpg 980w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Using-Anonymous-Functions-in-R-520x239.jpg 520w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/a><\/p>\n<p>In some cases, this construct with anonymous functions is useful, especially when you want to use functions that can be\u00a0only written in a little code and are not used anywhere else in your script.<\/p>\n<h2>Summary<\/h2>\n<p>We have learned about all the arguments that are used in the R programming language. As you can see, they are very useful and it also reduces the hassles of programmers.<\/p>\n<p><em><strong>Get ready to play an amazing <a href=\"https:\/\/data-flair.training\/blogs\/r-programming-quiz-part-1\/\">R Programming Online Quiz<\/a>!<\/strong><\/em><\/p>\n<p>If you have come across with any questions in your mind, feel free to ask in the comment section below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>With this tutorial, you will get a complete understanding of R function arguments. Firstly, we will discuss about the arguments in R language and process to add more arguments in R. You will also&#46;&#46;&#46;<\/p>\n","protected":false},"author":6,"featured_media":63447,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[51],"tags":[20608,20089,20088,20087],"class_list":["post-2786","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-r","tag-arguments-in-r","tag-r-anonymous-function","tag-r-dot-argument","tag-r-mult-argument"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Arguments in R Programming Language - Get a Deep Insight! - DataFlair<\/title>\n<meta name=\"description\" content=\"Learn to add &amp; use all the arguments in R; anonymous functions, functions as arguments, dots argument, default value and mult argument from this self explanatory guide.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/r-arguments-introduction\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Arguments in R Programming Language - Get a Deep Insight! - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Learn to add &amp; use all the arguments in R; anonymous functions, functions as arguments, dots argument, default value and mult argument from this self explanatory guide.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/r-arguments-introduction\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2017-06-09T11:26:19+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-08-25T12:51:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Arguments-in-R-02.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"802\" \/>\n\t<meta property=\"og:image:height\" content=\"420\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Arguments in R Programming Language - Get a Deep Insight! - DataFlair","description":"Learn to add & use all the arguments in R; anonymous functions, functions as arguments, dots argument, default value and mult argument from this self explanatory guide.","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:\/\/data-flair.training\/blogs\/r-arguments-introduction\/","og_locale":"en_US","og_type":"article","og_title":"Arguments in R Programming Language - Get a Deep Insight! - DataFlair","og_description":"Learn to add & use all the arguments in R; anonymous functions, functions as arguments, dots argument, default value and mult argument from this self explanatory guide.","og_url":"https:\/\/data-flair.training\/blogs\/r-arguments-introduction\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2017-06-09T11:26:19+00:00","article_modified_time":"2021-08-25T12:51:00+00:00","og_image":[{"width":802,"height":420,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Arguments-in-R-02.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/r-arguments-introduction\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/r-arguments-introduction\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/2c58ecb4f73a39f0ef993f1ddfcd7b89"},"headline":"Arguments in R Programming Language &#8211; Get a Deep Insight!","datePublished":"2017-06-09T11:26:19+00:00","dateModified":"2021-08-25T12:51:00+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/r-arguments-introduction\/"},"wordCount":1002,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/r-arguments-introduction\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Arguments-in-R-1.jpg","keywords":["Arguments in R","R Anonymous Function","R Dot Argument","R mult Argument"],"articleSection":["R Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/r-arguments-introduction\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/r-arguments-introduction\/","url":"https:\/\/data-flair.training\/blogs\/r-arguments-introduction\/","name":"Arguments in R Programming Language - Get a Deep Insight! - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/r-arguments-introduction\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/r-arguments-introduction\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Arguments-in-R-1.jpg","datePublished":"2017-06-09T11:26:19+00:00","dateModified":"2021-08-25T12:51:00+00:00","description":"Learn to add & use all the arguments in R; anonymous functions, functions as arguments, dots argument, default value and mult argument from this self explanatory guide.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/r-arguments-introduction\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/r-arguments-introduction\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/r-arguments-introduction\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Arguments-in-R-1.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/06\/Arguments-in-R-1.jpg","width":802,"height":420,"caption":"Arguments in R Programming"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/r-arguments-introduction\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"R Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/r\/"},{"@type":"ListItem","position":3,"name":"Arguments in R Programming Language &#8211; Get a Deep Insight!"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/2c58ecb4f73a39f0ef993f1ddfcd7b89","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"The DataFlair Team provides industry-driven content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our expert educators focus on delivering value-packed, easy-to-follow resources for tech enthusiasts and professionals.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam2\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/2786","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=2786"}],"version-history":[{"count":12,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/2786\/revisions"}],"predecessor-version":[{"id":63451,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/2786\/revisions\/63451"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/63447"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=2786"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=2786"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=2786"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}