{"id":9297,"date":"2019-12-03T11:40:48","date_gmt":"2019-12-03T06:10:48","guid":{"rendered":"http:\/\/ivyproschool.com\/blog\/?p=9297"},"modified":"2021-06-11T14:40:32","modified_gmt":"2021-06-11T09:10:32","slug":"write-your-own-functions-in-r-iii","status":"publish","type":"post","link":"https:\/\/ivyproschool.com\/blog\/write-your-own-functions-in-r-iii\/","title":{"rendered":"Write Your Own Functions in R \u2013 III"},"content":{"rendered":"<p><a href=\"https:\/\/ivyproschool.com\/blog\/write-your-own-functions-in-r-iii\/\"><br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-9248\" src=\"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/Fresh-Aqua-Summit.png\" alt=\"write your own functions in R\" width=\"400\" height=\"200\" srcset=\"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/Fresh-Aqua-Summit.png 400w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/Fresh-Aqua-Summit-300x150.png 300w\" sizes=\"auto, (max-width: 400px) 100vw, 400px\" \/><\/a><\/p>\n<p>Welcome to the third article of my series &#8220;Writing your own functions in R&#8221;. This weekend we will see how we can create attractive excel reports using\u00a0<strong>openxlsx<\/strong>\u00a0package.<\/p>\n<p>In the previous article, we wrote a function that iterates through all &#8220;.xlsx&#8221; files stored within a folder and while scanning through individual files, it would print the name of the file, number of sheets present in it and the names of all sheets in the file. Finally, it would also generate a data frame storing all of the above information. In this article, we will use some of the functions in R from <strong>openxlsx<\/strong>\u00a0package within a function that we will write to create some excel reports.<\/p>\n<p>Let us break this article down in 3 parts<\/p>\n<ol>\n<li>Learn how to write data frames stored in the R environment into files with the &#8220;.xlsx&#8221; extension, this is pretty simple.<\/li>\n<li>Learn how to write multiple data frames into different sheets of a &#8220;.xlsx&#8221; file using functions from <strong>openxlsx<\/strong> This we will learn in two different ways.<\/li>\n<li>Create custom styling for header and body for data frames to be written into excel files and applying them within a custom function.<\/li>\n<\/ol>\n<p>Let us start by creating a random data frame. We shall use the function,\u00a0<strong>expand.grid<\/strong>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-9298\" src=\"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/1-2.png\" alt=\"random data frame\" width=\"943\" height=\"393\" srcset=\"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/1-2.png 943w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/1-2-300x125.png 300w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/1-2-768x320.png 768w\" sizes=\"auto, (max-width: 943px) 100vw, 943px\" \/><\/p>\n<p>Now, writing this data frame in an excel file is pretty simple, though there are two different ways of doing this. Let us see those below,<\/p>\n<h3>Option 1<\/h3>\n<p>[php]<\/p>\n<p>############Snippet 2##################<br \/>\nwrite.xlsx(popn,&quot;popn.xlsx&quot;)<\/p>\n<p>### Option 2 ###<\/p>\n<p>### More Relevant while adding multiple sheets in an excel file ###<\/p>\n<p>wb&amp;lt;-createWorkbook() # Create an empty WorkBook<\/p>\n<p>addWorksheet(wb,&quot;Sheet1&quot;,gridLines = T) # Add an empty Worksheet in the WB<\/p>\n<p>writeData(wb,&quot;Sheet1&quot;,popn) # Write the Data Frame in the added Worksheet<\/p>\n<p>saveWorkbook(wb,&quot;popn.xlsx&quot;) # Save the WorkBook as an excel file.<\/p>\n<p>[\/php]<\/p>\n<p>Both the ways used above produce the same outputs, the advantage of using the second option over the first one is that we can add multiple sheets in an excel file using the later.<\/p>\n<p>Let us now try adding multiple data frames in different sheets of an excel file. For that, we need to generate an additional data frame. We will do this in a similar fashion as before using <strong>expand.grid<\/strong>.<\/p>\n<pre><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-9299\" src=\"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/2-5.png\" alt=\"expand.grid\" width=\"945\" height=\"374\" srcset=\"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/2-5.png 945w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/2-5-300x119.png 300w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/2-5-768x304.png 768w\" sizes=\"auto, (max-width: 945px) 100vw, 945px\" \/><\/pre>\n<p>Now simply using the first option as before we cannot add multiple sheets within the same excel workbook, for that, we will create a named list.<\/p>\n<p>The names of elements within the list will be the names of sheets to be added in the workbook, while the elements will be the data frames we wish to add in those sheets. The other way around is similar to the second option we have seen above, however since that is a little repetitive we can use a loop to ease our task.<\/p>\n<h4>Read Now: <a href=\"https:\/\/ivyproschool.com\/blog\/2019\/11\/28\/write-your-own-functions-in-r-ii\/\" target=\"_blank\" rel=\"noopener noreferrer\">Write Your Own Functions in R \u2013 II<\/a><\/h4>\n<p>Let us see these below:<\/p>\n<p>[php]<\/p>\n<p>############################# Option 1 ###############################<\/p>\n<p>list_of_data&lt;- list(&quot;Population&quot;=popn, &quot;Schedule&quot;= schedule)<\/p>\n<p>write.xlsx(list_of_data,&quot;Dataframes.xlsx&quot;)<\/p>\n<p>############################ Option 2 ################################<\/p>\n<p>wb&lt;-createWorkbook() # Create Empty Work Book<\/p>\n<p>addWorksheet(wb,&quot;Population&quot;,gridLines = T) # Add First WorkSheet<\/p>\n<p>addWorksheet(wb,&quot;Schedule&quot;,gridLines = T) # Add Second WorkSheet<\/p>\n<p>writeData(wb,&quot;Population&quot;,popn) # Add &quot;popn&quot; to WorkSheet 1<\/p>\n<p>writeData(wb,&quot;Schedule&quot;,schedule) # Add &quot;schedule&quot; to WorkSheet 2<\/p>\n<p>saveWorkbook(wb,&quot;Dataframes.xlsx&quot;) # Save WorkBook<\/p>\n<p>[\/php]<\/p>\n<p>The second way of doing this again looks pretty repetitive and manual. However, we can make it more efficient by writing a simple loop,<\/p>\n<p>[php]<\/p>\n<p>list_of_data&lt;- list(&quot;Population&quot;=popn, &quot;Schedule&quot;= schedule)<\/p>\n<p>Z=0<\/p>\n<p>wb&lt;- createWorkbook()<\/p>\n<p>for(i in 1:length(list_of_files)){<br \/>\nZ=Z+1<br \/>\naddWorksheet(wb,names(list_of_files[Z]),gridLines = T)<br \/>\nwriteData(wb,Z,list_of_files[[Z]],withFilter = F)<br \/>\nsetColWidths(wb, sheet = Z, cols = 1:ncol(list_of_files[[Z]]),<br \/>\nwidths = &quot;auto&quot;)<br \/>\n}<\/p>\n<p>if(Z==length(list_of_files)){<br \/>\nsuppressMessages(saveWorkbook(wb,file = &quot;Dataframes.xlsx&quot;,overwrite = T))<\/p>\n<p>}<\/p>\n<p>######################### Create a Function out of it ###########################<\/p>\n<p>write_files_xlsx&lt;-function(list_files){<br \/>\nZ=0<br \/>\nwb&lt;- createWorkbook()<br \/>\nfor(i in 1:length(list_of_files)){<br \/>\nZ=Z+1<br \/>\naddWorksheet(wb,names(list_of_files[Z]),gridLines = T)<br \/>\nwriteData(wb,Z,list_of_files[[Z]],withFilter = F)<br \/>\nsetColWidths(wb, sheet = Z, cols = 1:ncol(list_of_files[[Z]]),<br \/>\nwidths = &quot;auto&quot;)<br \/>\n}<br \/>\nif(Z==length(list_of_files)){<br \/>\nsuppressMessages(saveWorkbook(wb,file = &quot;Dataframes.xlsx&quot;,overwrite = T))<br \/>\nmessage(&quot;Dataframe Generated!&quot;)<br \/>\n}<\/p>\n<p>}<\/p>\n<p>&gt; write_files_xlsx&lt;-function(list_files = list_of_files)<br \/>\nDataframe Generated!<\/p>\n<p>[\/php]<\/p>\n<p>The excel file generated looks like this:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-9300\" src=\"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/3-1.png\" alt=\"look\" width=\"1280\" height=\"720\" srcset=\"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/3-1.png 1280w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/3-1-300x169.png 300w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/3-1-768x432.png 768w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/3-1-1024x576.png 1024w\" sizes=\"auto, (max-width: 1280px) 100vw, 1280px\" \/><\/p>\n<h4>Read Now: <a href=\"https:\/\/ivyproschool.com\/blog\/2019\/10\/14\/myths-data-science-career\/\" target=\"_blank\" rel=\"noopener noreferrer\">Top 10 Myths about Data Science Career<\/a><\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-9301 size-full\" src=\"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/4.png\" alt=\"look of excel\" width=\"1280\" height=\"720\" srcset=\"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/4.png 1280w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/4-300x169.png 300w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/4-768x432.png 768w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/4-1024x576.png 1024w\" sizes=\"auto, (max-width: 1280px) 100vw, 1280px\" \/><\/p>\n<p>These sheets look similar to normal excel sheets but without any formatting. But what if we would like to add a little more style to their appearance.<\/p>\n<p>For example, I usually like the font size to be 9, the headers to be a little different so to distinguish from the body and probably add a thin border all around the cells.<\/p>\n<p>All of this can be done in excel with a few simple steps and fortunately, this can be done even while generating these files from within R. All we need to do is add some <em>&#8220;Style Statements&#8221;\u00a0<\/em>to our code and make the files look prettier.<\/p>\n<p>Let us see those below,<\/p>\n<p>[php]<\/p>\n<p>############################# Create Styles #################################<\/p>\n<p>mystyle&lt;-createStyle(fontSize = 9,border = c(&quot;top&quot;, &quot;bottom&quot;, &quot;left&quot;, &quot;right&quot;),borderStyle = &quot;thin&quot;,halign = &quot;center&quot;,valign = &quot;center&quot;)<\/p>\n<p>headerStyle &lt;- createStyle(fontSize = 9, fontColour = &quot;#FFFFFF&quot;, halign = &quot;center&quot;,<br \/>\nfgFill = &quot;#4F81BD&quot;, border=c(&quot;top&quot;, &quot;bottom&quot;, &quot;left&quot;, &quot;right&quot;), borderColour = &quot;#4F81BD&quot;, textDecoration = &quot;bold&quot;)<\/p>\n<p>################## Use Defined Styles inside the Function ###################<\/p>\n<p>write_files_xlsx&lt;-function(list_files){<\/p>\n<p>Z=0<\/p>\n<p>wb&lt;- createWorkbook()<\/p>\n<p>mystyle&lt;-createStyle(fontSize = 9,border = c(&quot;top&quot;, &quot;bottom&quot;, &quot;left&quot;, &quot;right&quot;),borderStyle = &quot;thin&quot;,halign = &quot;center&quot;,valign = &quot;center&quot;)<\/p>\n<p>headerStyle &lt;- createStyle(fontSize = 9, fontColour = &quot;#FFFFFF&quot;, halign = &quot;center&quot;, fgFill = &quot;#4F81BD&quot;, border=c(&quot;top&quot;, &quot;bottom&quot;, &quot;left&quot;, &quot;right&quot;), borderColour = &quot;#4F81BD&quot;, textDecoration = &quot;bold&quot;)<\/p>\n<p>for(i in 1:length(list_of_files)){<br \/>\nZ=Z+1<br \/>\naddWorksheet(wb,names(list_of_files[Z]),gridLines = T)<br \/>\nwriteData(wb,Z,list_of_files[[Z]],withFilter = F, headerStyle = headerStyle)<br \/>\naddStyle(wb,sheet = Z,mystyle,rows =1:nrow(list_of_files[[Z]])+1 ,cols = 1:ncol(list_of_files[[Z]]),gridExpand = T)<br \/>\nsetColWidths(wb, sheet = Z, cols = 1:ncol(list_of_files[[Z]]),<br \/>\nwidths = &quot;auto&quot;)<br \/>\n}<br \/>\nif(Z==length(list_of_files)){<br \/>\nsuppressMessages(saveWorkbook(wb,file = &quot;Dataframes.xlsx&quot;,overwrite = T))<br \/>\nmessage(&quot;Dataframes Generated!&quot;)<br \/>\n}<\/p>\n<p>}<\/p>\n<p>&gt; write_files_xlsx(list_files = list_of_files)<br \/>\nDataframe Generated!<\/p>\n<p>[\/php]<\/p>\n<p>Let us take a look at the generated data frame again,<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-9302 size-full\" src=\"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/5.png\" alt=\"final look in excel\" width=\"1280\" height=\"720\" srcset=\"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/5.png 1280w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/5-300x169.png 300w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/5-768x432.png 768w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/5-1024x576.png 1024w\" sizes=\"auto, (max-width: 1280px) 100vw, 1280px\" \/><\/p>\n<p>Much better right? We can add many more such customization using different features within the package. For example, if I wanted the data to be formatted as a table, I could simply replace\u00a0<strong>writeData()\u00a0<\/strong>with\u00a0<strong>writeDataTable()<\/strong>.<\/p>\n<p>Finally, we can integrate this together with other custom functions in R to make tasks easier for us. That is all for today&#8217;s article. See you all again in the next one! Till then.., Ciao!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Welcome to the third article of my series &#8220;Writing your own functions in R&#8221;. This weekend we will see how we can create attractive excel reports using\u00a0openxlsx\u00a0package. In the previous article, we wrote a function that iterates through all &#8220;.xlsx&#8221; files stored within a folder and while scanning through individual files, it would print the name of the file, number of sheets present in it and the names of all sheets in the file. Finally, it would also generate a data frame storing all of the above information. In this article, we will use some of the functions in R from openxlsx\u00a0package within a function that we will write to create some excel reports. Let us break this article down in 3 parts Learn how to write data frames stored in the R environment into files with the &#8220;.xlsx&#8221; extension, this is pretty simple. Learn how to write multiple data frames into different sheets of a &#8220;.xlsx&#8221; file using functions from openxlsx This we will learn in two different ways. Create custom styling for header and body for data frames to be written into excel files and applying them within a custom function. Let us start by creating a random [&hellip;]<\/p>\n","protected":false},"author":1001944,"featured_media":9248,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[851,5,881,715],"tags":[748,751,737,752,369,749,750],"class_list":["post-9297","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-business-analytics","category-data-analytics","category-data-science","category-machine-learning-ai","tag-excel","tag-expand-grid","tag-functions","tag-openxlsx","tag-r","tag-writedata","tag-writedatatable"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Functions In R - Series 3 | Official Blog | Ivy Professional School<\/title>\n<meta name=\"description\" content=\"This article will help you have a better and sound understanding in writing your own functions in R, Read Now to have a better understanding in 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:\/\/ivyproschool.com\/blog\/write-your-own-functions-in-r-iii\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Functions In R - Series 3 | Official Blog | Ivy Professional School\" \/>\n<meta property=\"og:description\" content=\"This article will help you have a better and sound understanding in writing your own functions in R, Read Now to have a better understanding in R functions.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ivyproschool.com\/blog\/write-your-own-functions-in-r-iii\/\" \/>\n<meta property=\"og:site_name\" content=\"R vs Python: Which Analytics Tool Should You Choose for Data Science?\" \/>\n<meta property=\"article:published_time\" content=\"2019-12-03T06:10:48+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-06-11T09:10:32+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/Fresh-Aqua-Summit.png\" \/>\n\t<meta property=\"og:image:width\" content=\"400\" \/>\n\t<meta property=\"og:image:height\" content=\"200\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Anubinda\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Anubinda\" \/>\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\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/write-your-own-functions-in-r-iii\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/write-your-own-functions-in-r-iii\\\/\"},\"author\":{\"name\":\"Anubinda\",\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/#\\\/schema\\\/person\\\/2bc5b4bcba5e1696d75ce6924ed8ff13\"},\"headline\":\"Write Your Own Functions in R \u2013 III\",\"datePublished\":\"2019-12-03T06:10:48+00:00\",\"dateModified\":\"2021-06-11T09:10:32+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/write-your-own-functions-in-r-iii\\\/\"},\"wordCount\":1239,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/write-your-own-functions-in-r-iii\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/wp-content\\\/uploads\\\/2015\\\/08\\\/Fresh-Aqua-Summit.png\",\"keywords\":[\"excel\",\"expand.grid\",\"functions\",\"openxlsx\",\"R\",\"writedata\",\"writedatatable\"],\"articleSection\":[\"Business Analytics\",\"Data Analytics\",\"Data Science\",\"Machine Learning &amp; AI\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/write-your-own-functions-in-r-iii\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/write-your-own-functions-in-r-iii\\\/\",\"url\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/write-your-own-functions-in-r-iii\\\/\",\"name\":\"Functions In R - Series 3 | Official Blog | Ivy Professional School\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/write-your-own-functions-in-r-iii\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/write-your-own-functions-in-r-iii\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/wp-content\\\/uploads\\\/2015\\\/08\\\/Fresh-Aqua-Summit.png\",\"datePublished\":\"2019-12-03T06:10:48+00:00\",\"dateModified\":\"2021-06-11T09:10:32+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/#\\\/schema\\\/person\\\/2bc5b4bcba5e1696d75ce6924ed8ff13\"},\"description\":\"This article will help you have a better and sound understanding in writing your own functions in R, Read Now to have a better understanding in R functions.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/write-your-own-functions-in-r-iii\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/write-your-own-functions-in-r-iii\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/write-your-own-functions-in-r-iii\\\/#primaryimage\",\"url\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/wp-content\\\/uploads\\\/2015\\\/08\\\/Fresh-Aqua-Summit.png\",\"contentUrl\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/wp-content\\\/uploads\\\/2015\\\/08\\\/Fresh-Aqua-Summit.png\",\"width\":400,\"height\":200,\"caption\":\"write your own functions in R\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/write-your-own-functions-in-r-iii\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Write Your Own Functions in R \u2013 III\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/\",\"name\":\"Ivy Professional School | Official Blog\",\"description\":\"Confused between R and Python for your data science journey? Discover the key differences in data visualization, handling capabilities, speed, and ease of learning.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/#\\\/schema\\\/person\\\/2bc5b4bcba5e1696d75ce6924ed8ff13\",\"name\":\"Anubinda\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/2feb5b53215dd696c5aa800e5d4491f5402ef5f8647b9a2a6b9fe300a5885e9d?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/2feb5b53215dd696c5aa800e5d4491f5402ef5f8647b9a2a6b9fe300a5885e9d?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/2feb5b53215dd696c5aa800e5d4491f5402ef5f8647b9a2a6b9fe300a5885e9d?s=96&d=mm&r=g\",\"caption\":\"Anubinda\"},\"url\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/author\\\/anubinda\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Functions In R - Series 3 | Official Blog | Ivy Professional School","description":"This article will help you have a better and sound understanding in writing your own functions in R, Read Now to have a better understanding in 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:\/\/ivyproschool.com\/blog\/write-your-own-functions-in-r-iii\/","og_locale":"en_US","og_type":"article","og_title":"Functions In R - Series 3 | Official Blog | Ivy Professional School","og_description":"This article will help you have a better and sound understanding in writing your own functions in R, Read Now to have a better understanding in R functions.","og_url":"https:\/\/ivyproschool.com\/blog\/write-your-own-functions-in-r-iii\/","og_site_name":"R vs Python: Which Analytics Tool Should You Choose for Data Science?","article_published_time":"2019-12-03T06:10:48+00:00","article_modified_time":"2021-06-11T09:10:32+00:00","og_image":[{"width":400,"height":200,"url":"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/Fresh-Aqua-Summit.png","type":"image\/png"}],"author":"Anubinda","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Anubinda","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/ivyproschool.com\/blog\/write-your-own-functions-in-r-iii\/#article","isPartOf":{"@id":"https:\/\/ivyproschool.com\/blog\/write-your-own-functions-in-r-iii\/"},"author":{"name":"Anubinda","@id":"https:\/\/ivyproschool.com\/blog\/#\/schema\/person\/2bc5b4bcba5e1696d75ce6924ed8ff13"},"headline":"Write Your Own Functions in R \u2013 III","datePublished":"2019-12-03T06:10:48+00:00","dateModified":"2021-06-11T09:10:32+00:00","mainEntityOfPage":{"@id":"https:\/\/ivyproschool.com\/blog\/write-your-own-functions-in-r-iii\/"},"wordCount":1239,"commentCount":0,"image":{"@id":"https:\/\/ivyproschool.com\/blog\/write-your-own-functions-in-r-iii\/#primaryimage"},"thumbnailUrl":"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/Fresh-Aqua-Summit.png","keywords":["excel","expand.grid","functions","openxlsx","R","writedata","writedatatable"],"articleSection":["Business Analytics","Data Analytics","Data Science","Machine Learning &amp; AI"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/ivyproschool.com\/blog\/write-your-own-functions-in-r-iii\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/ivyproschool.com\/blog\/write-your-own-functions-in-r-iii\/","url":"https:\/\/ivyproschool.com\/blog\/write-your-own-functions-in-r-iii\/","name":"Functions In R - Series 3 | Official Blog | Ivy Professional School","isPartOf":{"@id":"https:\/\/ivyproschool.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/ivyproschool.com\/blog\/write-your-own-functions-in-r-iii\/#primaryimage"},"image":{"@id":"https:\/\/ivyproschool.com\/blog\/write-your-own-functions-in-r-iii\/#primaryimage"},"thumbnailUrl":"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/Fresh-Aqua-Summit.png","datePublished":"2019-12-03T06:10:48+00:00","dateModified":"2021-06-11T09:10:32+00:00","author":{"@id":"https:\/\/ivyproschool.com\/blog\/#\/schema\/person\/2bc5b4bcba5e1696d75ce6924ed8ff13"},"description":"This article will help you have a better and sound understanding in writing your own functions in R, Read Now to have a better understanding in R functions.","breadcrumb":{"@id":"https:\/\/ivyproschool.com\/blog\/write-your-own-functions-in-r-iii\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ivyproschool.com\/blog\/write-your-own-functions-in-r-iii\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ivyproschool.com\/blog\/write-your-own-functions-in-r-iii\/#primaryimage","url":"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/Fresh-Aqua-Summit.png","contentUrl":"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/Fresh-Aqua-Summit.png","width":400,"height":200,"caption":"write your own functions in R"},{"@type":"BreadcrumbList","@id":"https:\/\/ivyproschool.com\/blog\/write-your-own-functions-in-r-iii\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/ivyproschool.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Write Your Own Functions in R \u2013 III"}]},{"@type":"WebSite","@id":"https:\/\/ivyproschool.com\/blog\/#website","url":"https:\/\/ivyproschool.com\/blog\/","name":"Ivy Professional School | Official Blog","description":"Confused between R and Python for your data science journey? Discover the key differences in data visualization, handling capabilities, speed, and ease of learning.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ivyproschool.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/ivyproschool.com\/blog\/#\/schema\/person\/2bc5b4bcba5e1696d75ce6924ed8ff13","name":"Anubinda","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/2feb5b53215dd696c5aa800e5d4491f5402ef5f8647b9a2a6b9fe300a5885e9d?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/2feb5b53215dd696c5aa800e5d4491f5402ef5f8647b9a2a6b9fe300a5885e9d?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2feb5b53215dd696c5aa800e5d4491f5402ef5f8647b9a2a6b9fe300a5885e9d?s=96&d=mm&r=g","caption":"Anubinda"},"url":"https:\/\/ivyproschool.com\/blog\/author\/anubinda\/"}]}},"_links":{"self":[{"href":"https:\/\/ivyproschool.com\/blog\/wp-json\/wp\/v2\/posts\/9297","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ivyproschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ivyproschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ivyproschool.com\/blog\/wp-json\/wp\/v2\/users\/1001944"}],"replies":[{"embeddable":true,"href":"https:\/\/ivyproschool.com\/blog\/wp-json\/wp\/v2\/comments?post=9297"}],"version-history":[{"count":1,"href":"https:\/\/ivyproschool.com\/blog\/wp-json\/wp\/v2\/posts\/9297\/revisions"}],"predecessor-version":[{"id":10589,"href":"https:\/\/ivyproschool.com\/blog\/wp-json\/wp\/v2\/posts\/9297\/revisions\/10589"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ivyproschool.com\/blog\/wp-json\/wp\/v2\/media\/9248"}],"wp:attachment":[{"href":"https:\/\/ivyproschool.com\/blog\/wp-json\/wp\/v2\/media?parent=9297"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ivyproschool.com\/blog\/wp-json\/wp\/v2\/categories?post=9297"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ivyproschool.com\/blog\/wp-json\/wp\/v2\/tags?post=9297"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}