

{"id":2653,"date":"2017-05-26T07:30:49","date_gmt":"2017-05-26T02:00:49","guid":{"rendered":"http:\/\/data-flair.training\/blogs\/?p=2653"},"modified":"2021-08-25T18:21:01","modified_gmt":"2021-08-25T12:51:01","slug":"r-function","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/r-function\/","title":{"rendered":"Functions in R | Gain Expertise in its Usage with Various Methods!"},"content":{"rendered":"<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:2353,&quot;href&quot;:&quot;https:\\\/\\\/www.r-project.org\\\/search.html&quot;,&quot;archived_href&quot;:&quot;http:\\\/\\\/web-wp.archive.org\\\/web\\\/20250923123757\\\/https:\\\/\\\/www.r-project.org\\\/search.html&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2025-12-11 04:07:28&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-14 23:44:41&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-31 02:21:30&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-21 16:24:44&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-26 21:47:09&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-03 11:33:26&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-13 06:19:02&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-31 13:57:34&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-10 01:40:20&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-04-21 12:01:39&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-22 12:35:43&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-25 12:39:55&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-29 01:55:25&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-06-06 07:38:34&quot;,&quot;http_code&quot;:206}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-06-06 07:38:34&quot;,&quot;http_code&quot;:206},&quot;process&quot;:&quot;done&quot;}]'><\/div>\n<p>Now, it&#8217;s time to uncover one of the most essential concepts of R programming that is R function. We will cover every aspect related to it in this tutorial. And, I assure you that\u00a0after completion of this article, you will never scratch your head while using R functions.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/R-Functions-tutorial-1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-62159\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/R-Functions-tutorial-1.jpg\" alt=\"R Functions tutorial\" width=\"802\" height=\"420\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/R-Functions-tutorial-1.jpg 802w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/R-Functions-tutorial-1-150x79.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/R-Functions-tutorial-1-300x157.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/R-Functions-tutorial-1-768x402.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/R-Functions-tutorial-1-520x272.jpg 520w\" sizes=\"auto, (max-width: 802px) 100vw, 802px\" \/><\/a><\/p>\n<p>So, let&#8217;s start the tutorial.<\/p>\n<h2>What is R?<\/h2>\n<p><em>R is an open-source and free programming language that provides various facilities for statistical computation and graphics.<\/em>\u00a0Due to its wide range of packages, R has become the primary tool for statistical computing by statisticians and data miners for the development of statistical software in order to carry out data analysis as well as data visualisation.<\/p>\n<p>Let us now look at some key capabilities of R:<\/p>\n<ul>\n<li>R is easily extensible through functions and extensions.<\/li>\n<li>It provides effective data handling and manipulation components.<\/li>\n<li>It provides tools specific to a wide variety of data analysis.<\/li>\n<li>R has several operators for calculations on arrays and other types of ordered data.<\/li>\n<li>It provides advanced visualization capabilities through different tools available.<\/li>\n<\/ul>\n<p><em><strong>You must definitely check the <a href=\"https:\/\/data-flair.training\/blogs\/r-packages-tutorial\/\">R Packages tutorial<\/a><\/strong><\/em><\/p>\n<h3>Moving from Scripts to R Function<\/h3>\n<p>R function provides two major advantages over the script:<\/p>\n<ul>\n<li>Functions can work with any input. You can provide diverse input data to the functions.<\/li>\n<li>The output of the function is an object that allows you to work with the result.<\/li>\n<\/ul>\n<h4>How to Create a Script in R?<\/h4>\n<p>We will now learn the methodology of creating a script in R.<\/p>\n<p>As we know, R supports several editors. So the script can be created in any of the editors like Notepad, MS Word or Word Pad and can be saved with R extension in the current working directory.<\/p>\n<p>Now to read the file in R, source function can be used.<\/p>\n<p>For example, if we want to read the sample.R script in R, we need to provide below command:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">source(\"sample.R\")<\/pre>\n<p>This will read the file sample in R.<\/p>\n<p>In order to create a script, first, open a script file in the editor mode and type the required code.<\/p>\n<p>We will create a script that takes in input in the form of fractions and converts it into a percentage by further rounding it to one decimal digit.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; #Author DataFlair\r\n&gt; frac &lt;- c(0.452, 1.5642, 0.84520)\r\n&gt; percentage &lt;- round(frac * 100, digits = 1)\r\n&gt; out &lt;- paste(percentage, \"%\", sep = \"\")\r\n&gt; print(out)\r\n<\/pre>\n<p>That is, you need to give values that you want to convert to a percentage as input and then convert it into percentage and round off to required places. Then put the % sign and display the answer.<\/p>\n<p>Save the above script as script file with any name for example pastePercent.R.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/3.-i.-How-to-create-a-Script-in-R_.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-60727 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/3.-i.-How-to-create-a-Script-in-R_.jpg\" alt=\"pastepercent.R input - R Functions\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/3.-i.-How-to-create-a-Script-in-R_.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/3.-i.-How-to-create-a-Script-in-R_-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/3.-i.-How-to-create-a-Script-in-R_-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/3.-i.-How-to-create-a-Script-in-R_-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/3.-i.-How-to-create-a-Script-in-R_-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/3.-i.-How-to-create-a-Script-in-R_-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p>Now you can call this script on the console with the help of source command which we have already seen.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">source(\u2018pastePercent.R\u2019)<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/3.-i.-ii.-source.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-60728 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/3.-i.-ii.-source.jpg\" alt=\"pastepercent.R output - R Functions\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/3.-i.-ii.-source.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/3.-i.-ii.-source-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/3.-i.-ii.-source-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/3.-i.-ii.-source-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/3.-i.-ii.-source-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/3.-i.-ii.-source-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p>This is how a script is written and executed in R.<\/p>\n<p><em><strong>Wait! Have you checked the <a href=\"https:\/\/data-flair.training\/blogs\/r-control-structures\/\">Control Structures in R<\/a><\/strong><\/em><\/p>\n<h4>Transforming the Script into R Function<\/h4>\n<p>Now, we are going to see how to convert R script into the function in R.<\/p>\n<p>Firstly, define a function with a name so that it becomes easier to call an R function and pass arguments to it as input.<\/p>\n<p>The R function should be followed by parentheses that act as a front gate for your function and between the parentheses, arguments for the function are provided.<\/p>\n<p>Use the return() statement that acts as a back gate of your function.<\/p>\n<p>The return() statement provides the final result of the function that is returned to your workspace.<\/p>\n<p>We will see this with an example below.<\/p>\n<p>Let us now see how we can convert the script that we had written earlier to convert values into percentage and round off into an R function.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">Percent_add &lt;- function(frac){\r\n  percent &lt;- round(frac * 100, digits = 1)\r\n  out &lt;- paste(percent, \"%\", sep = \"%\")\r\n  return(out)\r\n}\r\n<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/3.-ii.-Transforming-the-Script-into-R-Function.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-60729 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/3.-ii.-Transforming-the-Script-into-R-Function.jpg\" alt=\"Tranforming the script into R function\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/3.-ii.-Transforming-the-Script-into-R-Function.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/3.-ii.-Transforming-the-Script-into-R-Function-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/3.-ii.-Transforming-the-Script-into-R-Function-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/3.-ii.-Transforming-the-Script-into-R-Function-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/3.-ii.-Transforming-the-Script-into-R-Function-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/3.-ii.-Transforming-the-Script-into-R-Function-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p>The keyword <strong>function<\/strong> defines the starting of function. The <strong>parentheses<\/strong> after the function form the front gate, or argument list of the function. Between the parentheses are the arguments to the function. In this case, there is only one argument.<\/p>\n<p>The<strong> return<\/strong> statement defines the end of the function and returns the result. The object put between the parentheses is returned from inside the function to the workspace. Only one object can be placed between the parentheses.<\/p>\n<p>The braces, {} are the walls of the function. Everything between the braces is part of the assembly line or the body of the function. This is how functions are created in R.<\/p>\n<p><em><strong>Explore the <a href=\"https:\/\/data-flair.training\/blogs\/r-arguments-introduction\/\">different arguments in R programming<\/a><\/strong><\/em><\/p>\n<h3>Using R Function<\/h3>\n<p>After transforming the script into an R function, you need to save it and you can use the function in R again if required.<\/p>\n<p>As R does not let you know by itself that it loaded the function but it is present in the workspace, if you want you can check it by using <strong>ls()<\/strong> command.<\/p>\n<p>Now as we know what all functions in R are present in the memory and we can use it when required.<\/p>\n<p>For example, if you want to create percentage from values again, you can use add percent function for the same as below:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">#Author DataFlair\r\nls()\r\nnew.vector &lt;- c(0.8223, 0.02487, 1.62, 0.4)\r\nPercent_add(new.vector)\r\n<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<h2><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/4.-Using-R-Function.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-60730 size-full aligncenter\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/4.-Using-R-Function.jpg\" alt=\"using R Function\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/4.-Using-R-Function.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/4.-Using-R-Function-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/4.-Using-R-Function-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/4.-Using-R-Function-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/4.-Using-R-Function-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/4.-Using-R-Function-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/h2>\n<h3>Using the Function Objects in R<\/h3>\n<p>In R, a function is also an object and you can manipulate it as you do for other objects.<\/p>\n<p>You can assign a function to the new object using below command:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">percent_paste &lt;- Percent_add<\/pre>\n<p>Now<strong> percent_paste<\/strong>\u00a0is a function as well that does exactly the same as Percent_add. Note that, you do not add it after parenthesesPercent_add in this case. If you add the parentheses, you call the function and put the result of that call in\u00a0percent_paste. If you do not add the parentheses, you refer to the function object itself without calling it.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">percent_paste\r\n\r\nPercent_add &lt;- function(frac){\r\n  percentage &lt;- round(frac * 100, digits = 1)\r\n  out &lt;- paste(percentage, \"%\", sep = \"\")\r\n  return(out)\r\n}\r\n\r\nprint(Percent_add(new.vector))<\/pre>\n<p><b>Code Display:<\/b><\/p>\n<h2><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/5.-Using-the-Function-Objects-in-R.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-60731 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/5.-Using-the-Function-Objects-in-R.jpg\" alt=\"Using the Function Objects in R - Input\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/5.-Using-the-Function-Objects-in-R.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/5.-Using-the-Function-Objects-in-R-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/5.-Using-the-Function-Objects-in-R-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/5.-Using-the-Function-Objects-in-R-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/5.-Using-the-Function-Objects-in-R-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/5.-Using-the-Function-Objects-in-R-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/h2>\n<p>The output of the above code is as follows:<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/5.-Using-the-Function-Objects-in-R-Output.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-60732 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/5.-Using-the-Function-Objects-in-R-Output.jpg\" alt=\"Using the Function Objects in R - Output\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/5.-Using-the-Function-Objects-in-R-Output.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/5.-Using-the-Function-Objects-in-R-Output-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/5.-Using-the-Function-Objects-in-R-Output-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/5.-Using-the-Function-Objects-in-R-Output-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/5.-Using-the-Function-Objects-in-R-Output-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/5.-Using-the-Function-Objects-in-R-Output-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p><em><strong>Don&#8217;t forget to check the <a href=\"https:\/\/data-flair.training\/blogs\/r-vector-functions\/\">R Vector Functions Tutorial<\/a><\/strong><\/em><\/p>\n<h3>Reducing the Number of Lines in R<\/h3>\n<p>As of now, we have seen how to convert the script into a function and how to assign a function to the new object. All these include a large number of lines to be written.<\/p>\n<p>So, let us now understand how we can reduce the number of lines in R.<\/p>\n<p>There are basically two ways of doing it:<\/p>\n<ul>\n<li>Returning values by default<\/li>\n<li>Dropping {}<\/li>\n<\/ul>\n<p>Let us see the above ways in detail below:<\/p>\n<h4>1. Returning Values by Default in R<\/h4>\n<p>Till now, in all the above code, we have written <em>return()<\/em> function to return output. But in R, this can be skipped as by default, R returns the value of the last line of code in the R function body.<\/p>\n<p>Now, the above code will be:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">#Author DataFlair\r\nPercent_add &lt;- function(fac){ \r\npercentage &lt;- round(fac * 100, digits = 1) \r\npaste(percentage, \"%\", sep = \"\")}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<h3><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/6.i.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-60764 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/6.i.jpg\" alt=\"Returning Values by Default in R\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/6.i.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/6.i-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/6.i-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/6.i-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/6.i-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/6.i-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/h3>\n<p>You need return if you want to exit the function before the end of the code in the body.<\/p>\n<p>For example, you could add a line to the Percent_add function that checks whether fac is numeric, and if not, returns NULL, as shown in the following table:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">#Author DataFlair\r\nPercent_add &lt;- function(frac){\r\nif( !is.numeric(frac) ) return(NULL) \r\npercentage &lt;- round(frac * 100, digits = 1) \r\npaste(percentage, \"%\", sep = \"\")}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<h3><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/6.-i.-Returning-Values-by-Default-in-R-2.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-60734 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/6.-i.-Returning-Values-by-Default-in-R-2.jpg\" alt=\"Percent_add function\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/6.-i.-Returning-Values-by-Default-in-R-2.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/6.-i.-Returning-Values-by-Default-in-R-2-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/6.-i.-Returning-Values-by-Default-in-R-2-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/6.-i.-Returning-Values-by-Default-in-R-2-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/6.-i.-Returning-Values-by-Default-in-R-2-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/6.-i.-Returning-Values-by-Default-in-R-2-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/h3>\n<h4>2. Dropping the {}<\/h4>\n<p>You can drop braces in some cases though they form a <strong>proverbial wall<\/strong> around the function.<\/p>\n<p>If a function consists of only one line of code, you can just add that line after the argument list without enclosing it in braces. R will see the code after the argument list as the body of the function.<\/p>\n<p>Suppose, you want to calculate the odds from a proportion. You can write a function without using braces, as shown below:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; odds &lt;- function(x) x \/ (1-x)<\/pre>\n<p>Here no braces are used to write the function.<\/p>\n<p><em>Any doubts till now? Share your queries in the comment section.<\/em><\/p>\n<h3>Scope of R Function<\/h3>\n<p>Every object you create ends up in this environment, which is also called the global environment. The workspace or global environment is the universe of the R user where everything happens.<\/p>\n<p>There are two types of R functions as explained below:<\/p>\n<h4>1. External R Function<\/h4>\n<p>If you use an R function, the function first creates a temporary local environment. This local environment is nested within the global environment, which means that, from that local environment, you also can access any object from the global environment. As soon as the function ends, the local environment is destroyed along with all the objects in it.<\/p>\n<p>If R sees any object name, it first searches the local environment. If it finds the object there, it uses that one else it searches in the global environment for that object.<\/p>\n<h4>2. Internal R Function<\/h4>\n<p>Using global variables in an R function is not considered a good practice. Writing your functions in such a way that they need objects in the global environment is not efficient because you use functions to avoid dependency on objects in the global environment in the first place.<\/p>\n<p>The whole concept behind R strongly opposes using global variables used in different functions. As a functional programming language, one of the main ideas of R is that the outcome of a function should not be dependent on anything but the values for the arguments of that function. If you give the arguments for the same values, you will always get the same results.<\/p>\n<p>This characteristic of R may strike you as odd, but it has its merits. Sometimes you need to repeat some calculations a few times within a function, but these calculations only make sense inside that function.<\/p>\n<p>The below example shows the usage of internal function:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">#Author DataFlair\r\ncalculate_func &lt;- function(data1, data2, data3){\r\n  base_min &lt;- function(z) z - mean(data3)\r\n  base_min(data1) \/ base_min(data2)\r\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/7.ii_.-Internal-R-Function.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-60745 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/7.ii_.-Internal-R-Function.jpg\" alt=\"usage of R internal function\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/7.ii_.-Internal-R-Function.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/7.ii_.-Internal-R-Function-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/7.ii_.-Internal-R-Function-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/7.ii_.-Internal-R-Function-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/7.ii_.-Internal-R-Function-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/7.ii_.-Internal-R-Function-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p>The code for calculate.eff function is shown below:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; #Author DataFlair\r\n&gt; d1 &lt;- c(3.24, 2.21, 1.45)\r\n&gt; d2 &lt;- c(4.65, 5.12, 4.23)\r\n&gt; d3 &lt;- c(0.11, 0.20, 0.49, 0.28)\r\n&gt; calculate_func(d1,d2,d3)<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/7.ii_.-Internal-R-Function-Output.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-60748 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/7.ii_.-Internal-R-Function-Output.jpg\" alt=\" calculate.eff function\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/7.ii_.-Internal-R-Function-Output.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/7.ii_.-Internal-R-Function-Output-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/7.ii_.-Internal-R-Function-Output-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/7.ii_.-Internal-R-Function-Output-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/7.ii_.-Internal-R-Function-Output-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/7.ii_.-Internal-R-Function-Output-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p>A closer look at the R function definition of base_min() shows that it uses an object control but does not have an argument with that name.<\/p>\n<p><em><strong>Do you know about <a href=\"https:\/\/data-flair.training\/blogs\/r-matrix-functions\/\">Matrix Function in R<\/a><\/strong><\/em><\/p>\n<h3>Finding the Methods behind the Function<\/h3>\n<p>It is easy to find out the function you used in R. You can just look at the function code of print() by typing its name at the command line.<\/p>\n<p>In order to display the info code of the print() function, we proceed as follows:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">print<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<h3><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/8.-Finding-the-Methods-behind-the-Function.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-60750 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/8.-Finding-the-Methods-behind-the-Function.jpg\" alt=\"print() function in R\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/8.-Finding-the-Methods-behind-the-Function.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/8.-Finding-the-Methods-behind-the-Function-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/8.-Finding-the-Methods-behind-the-Function-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/8.-Finding-the-Methods-behind-the-Function-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/8.-Finding-the-Methods-behind-the-Function-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/8.-Finding-the-Methods-behind-the-Function-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/h3>\n<h4>1. The UseMethod() Function<\/h4>\n<p>How can that one line of code in the print() function do so many complex things, such as printing vectors, data frames, and lists, all in a different way?\u00a0The UseMethod() function contains the answer. This answer plays the role of a central function in the main generic function system.<\/p>\n<p>The UseMethod() function moves along and looks for a function that can deal with the type of object that is given as the argument x.<\/p>\n<p>Suppose you have a data frame that you want to print.\u00a0The object that was passed as an argument will be printed using the print.data.frame() function that will be first looked up by R.<\/p>\n<p>The other functions are searched through a thorough search of another function. The procedure is then started with a print which is then followed by the object type and the dot.<\/p>\n<p>The function print.data.frame() can also be called inside the code. This is explained in the coming section.<\/p>\n<h4>2. Calling Functions Inside Code<\/h4>\n<p>You can also call the function print.data.frame() yourself.<\/p>\n<p>Below is the example for the same:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; #Author DataFlair\r\n&gt; small_data &lt;- data.frame(c1 = 1:2, c2 = 2:1)\r\n&gt; print.data.frame(small_data)<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<h2><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/8.-ii.-Finding-the-Methods-behind-the-Function.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-60754 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/8.-ii.-Finding-the-Methods-behind-the-Function.jpg\" alt=\"Calling Functions Inside Code\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/8.-ii.-Finding-the-Methods-behind-the-Function.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/8.-ii.-Finding-the-Methods-behind-the-Function-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/8.-ii.-Finding-the-Methods-behind-the-Function-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/8.-ii.-Finding-the-Methods-behind-the-Function-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/8.-ii.-Finding-the-Methods-behind-the-Function-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/8.-ii.-Finding-the-Methods-behind-the-Function-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/h2>\n<h3>Using Default Methods in R<\/h3>\n<p>R provides the feature to create an object with the names that are already used by <a href=\"https:\/\/www.r-project.org\/search.html\">R<\/a>. It is possible with the use of default keyword.<\/p>\n<p>R will ignore the type of the object in that case and just look for a default method if you use the default keyword with the name of an object.<\/p>\n<p>Below example explains it:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; #Author DataFlair\r\n&gt; print.default(small_data)<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/9.-Using-Default-Methods-in-R.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-60757 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/9.-Using-Default-Methods-in-R.jpg\" alt=\"Using Default Methods in R - print default\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/9.-Using-Default-Methods-in-R.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/9.-Using-Default-Methods-in-R-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/9.-Using-Default-Methods-in-R-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/9.-Using-Default-Methods-in-R-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/9.-Using-Default-Methods-in-R-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/9.-Using-Default-Methods-in-R-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<h2>Summary<\/h2>\n<p>We discussed different methods to use R functions. Also, we learned about reducing the number of lines along with the default methods in R. At last, we explored the scope of R function.<\/p>\n<p><em><strong>Now, it&#8217;s time to learn about the<a href=\"https:\/\/data-flair.training\/blogs\/r-recursive-function\/\"> R Recursive Function<\/a><\/strong><\/em><\/p>\n<p>If you have any query regarding R function, do ask in the comment section.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Now, it&#8217;s time to uncover one of the most essential concepts of R programming that is R function. We will cover every aspect related to it in this tutorial. And, I assure you that\u00a0after&#46;&#46;&#46;<\/p>\n","protected":false},"author":6,"featured_media":62159,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[51],"tags":[20471,20470,20469,11194],"class_list":["post-2653","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-r","tag-default-methods-usage-in-r","tag-r-function-scope","tag-r-function-usage","tag-r-functions"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Functions in R | Gain Expertise in its Usage with Various Methods! - DataFlair<\/title>\n<meta name=\"description\" content=\"With this R functions tutorial, learn to create a script in R, usage of R function and function objects, reducing the number of lines along with scope of R functions.\" \/>\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-function\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Functions in R | Gain Expertise in its Usage with Various Methods! - DataFlair\" \/>\n<meta property=\"og:description\" content=\"With this R functions tutorial, learn to create a script in R, usage of R function and function objects, reducing the number of lines along with scope of R functions.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/r-function\/\" \/>\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-05-26T02:00:49+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-08-25T12:51:01+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/R-Functions-tutorial-1.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=\"11 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Functions in R | Gain Expertise in its Usage with Various Methods! - DataFlair","description":"With this R functions tutorial, learn to create a script in R, usage of R function and function objects, reducing the number of lines along with scope of R functions.","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-function\/","og_locale":"en_US","og_type":"article","og_title":"Functions in R | Gain Expertise in its Usage with Various Methods! - DataFlair","og_description":"With this R functions tutorial, learn to create a script in R, usage of R function and function objects, reducing the number of lines along with scope of R functions.","og_url":"https:\/\/data-flair.training\/blogs\/r-function\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2017-05-26T02:00:49+00:00","article_modified_time":"2021-08-25T12:51:01+00:00","og_image":[{"width":802,"height":420,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/R-Functions-tutorial-1.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":"11 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/r-function\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/r-function\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/2c58ecb4f73a39f0ef993f1ddfcd7b89"},"headline":"Functions in R | Gain Expertise in its Usage with Various Methods!","datePublished":"2017-05-26T02:00:49+00:00","dateModified":"2021-08-25T12:51:01+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/r-function\/"},"wordCount":1942,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/r-function\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/R-Functions-tutorial-1.jpg","keywords":["Default Methods Usage in R","R Function Scope","R Function Usage","R functions"],"articleSection":["R Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/r-function\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/r-function\/","url":"https:\/\/data-flair.training\/blogs\/r-function\/","name":"Functions in R | Gain Expertise in its Usage with Various Methods! - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/r-function\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/r-function\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/R-Functions-tutorial-1.jpg","datePublished":"2017-05-26T02:00:49+00:00","dateModified":"2021-08-25T12:51:01+00:00","description":"With this R functions tutorial, learn to create a script in R, usage of R function and function objects, reducing the number of lines along with scope of R functions.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/r-function\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/r-function\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/r-function\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/R-Functions-tutorial-1.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/05\/R-Functions-tutorial-1.jpg","width":802,"height":420,"caption":"R Functions tutorial"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/r-function\/#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":"Functions in R | Gain Expertise in its Usage with Various Methods!"}]},{"@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\/2653","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=2653"}],"version-history":[{"count":14,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/2653\/revisions"}],"predecessor-version":[{"id":62161,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/2653\/revisions\/62161"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/62159"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=2653"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=2653"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=2653"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}