

{"id":4208,"date":"2017-09-18T12:28:59","date_gmt":"2017-09-18T06:58:59","guid":{"rendered":"http:\/\/data-flair.training\/blogs\/?p=4208"},"modified":"2021-08-25T17:26:59","modified_gmt":"2021-08-25T11:56:59","slug":"r-vector-functions","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/r-vector-functions\/","title":{"rendered":"R Vector Functions &#8211; How to apply Functions over R Vectors"},"content":{"rendered":"<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:1282,&quot;href&quot;:&quot;https:\\\/\\\/www.r-project.org&quot;,&quot;archived_href&quot;:&quot;&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[],&quot;broken&quot;:false,&quot;last_checked&quot;:null,&quot;process&quot;:&quot;done&quot;}]'><\/div>\n<p>We are going to discuss R vector functions in this tutorial. They are the functions that can be applied over R vectors. We will explain all the functions with detailed examples to provide you with better command over the concept.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/R-Vector-Functions-2.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-59105\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/R-Vector-Functions-2.jpg\" alt=\"R Vector Functions\" width=\"802\" height=\"420\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/R-Vector-Functions-2.jpg 802w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/R-Vector-Functions-2-150x79.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/R-Vector-Functions-2-300x157.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/R-Vector-Functions-2-768x402.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/R-Vector-Functions-2-520x272.jpg 520w\" sizes=\"auto, (max-width: 802px) 100vw, 802px\" \/><\/a><\/p>\n<h2>What are R Vector Functions?<\/h2>\n<p>First of all, let&#8217;s discuss what exactly a function means. In order to perform a particular task, we make use of the function, which is a piece of code in R.\u00a0 In R, these functions are referred to as the objects as they facilitate the similar way of functioning like other types of objects.\u00a0 Functions that we use in R vectors are known as the vector functions.<\/p>\n<p><strong>For example<\/strong>: rep(), seq(), using all() and any(), more on c() etc.<\/p>\n<p><em><strong>Wait! Have you checked &#8211; <a href=\"https:\/\/data-flair.training\/blogs\/r-matrix-functions\/\">R Matrix Functions<\/a><\/strong><\/em><\/p>\n<p>Here we are going to discuss all these functions of the R vector in detail with examples.<\/p>\n<h3>1. R rep() Function<\/h3>\n<p><b>rep()\u00a0<\/b>is used for replicating the values in x. The two common cases that exhibit faster-simplified versions are rep.int and rep_len.\u00a0Furthermore, these functions are not generic.<\/p>\n<p>Let&#8217;s now discuss how we can apply this rep() to any vector with the help of examples.<strong>\u00a0<\/strong><\/p>\n<h4>1.1. How to repeat vectors in R<\/h4>\n<p>You can use the rep() function in several ways if you want to repeat the complete vector.<\/p>\n<p><strong>For example:<\/strong><\/p>\n<p><strong>a)<\/strong>\u00a0To repeat the vector c(0, 0, 7) three times, use this code:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; rep(c(0, 0, 7), times = 4)\r\n[1] 0 0 7 0 0 7 0 0 7 0 0 7<\/pre>\n<p><strong>b)<\/strong>\u00a0We can also repeat every value by specifying each argument, like this:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; rep(c(2, 4, 2), each = 2)\r\n[1] 2 2 4 4 2 2<\/pre>\n<p><strong>c)<\/strong>\u00a0For each value, we can tell R how often it has to repeat:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; rep(c(0, 7), times = c(4,3))\r\n[1] 0 0 0 0 7 7 7<\/pre>\n<p><strong>d)<\/strong>\u00a0In seq, we use the argument, length.out to define R. It will repeat the vector until it reaches the specified length, even if the last repetition is incomplete.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; rep(1:3,length.out=9)\r\n[1] 1 2 3 1 2 3 1 2 3<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/rep-vector-c.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-59081\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/rep-vector-c.jpg\" alt=\"rep vector c \" width=\"1366\" height=\"728\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/rep-vector-c.jpg 1366w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/rep-vector-c-150x80.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/rep-vector-c-300x160.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/rep-vector-c-768x409.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/rep-vector-c-1024x546.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/rep-vector-c-520x277.jpg 520w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/a><\/p>\n<p><em><strong>You should definitely check the <a href=\"https:\/\/data-flair.training\/blogs\/r-recursive-function\/\">R Recursive Function Tutorial<\/a><\/strong><\/em><\/p>\n<h3>2. R seq() Function<\/h3>\n<div>It generates regular sequences. The seq function is standard generic in nature that also has a default method.\u00a0\u00a0<strong>seq.int<\/strong>\u00a0poses a few restrictions due to its primitiveness but it is also much faster. The two common cases that exhibit fast primitives are seq_along and seq_len.<\/div>\n<p>Let&#8217;s now discuss how we can apply this seq() to any vector with the help of examples.<\/p>\n<h4>2.1. How to create vectors in R<\/h4>\n<p><strong>a)<\/strong>\u00a0In order to use integers to create vectors:<\/p>\n<p><strong>For example<\/strong>:<\/p>\n<p>To create a list of vectors over a specified range, we use the colon (:) symbol.<\/p>\n<p>The code 1:5 gives you a vector with the numbers 1 to 5, and 2:&#8211;5 create a vector with the numbers 2 to \u20135.<\/p>\n<p><strong>b)<\/strong>\u00a0Using the seq(), we make steps in a sequence. Seq() function is used to describe the intervals by which numbers\u00a0should decrease or increase.<\/p>\n<p><strong>For example<\/strong>:<\/p>\n<p>In R, a vector with numbers 4.5 to 3.0 in steps of 0.5.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; seq(from = 4.5, to = 3.0, by = -0.5)\r\n[1] 4.5 4.0 3.5 3.0<\/pre>\n<p><strong>c)<\/strong>\u00a0You can specify the length of the sequence by using the argument, length.out. Afterwards, R can calculate the step size by itself.<\/p>\n<p><strong>For example:<\/strong><\/p>\n<p>You can make a vector of nine values going from -2.7 to 1.3 like this:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; seq(from = -2.7, to = 1.3, length.out = 9)\r\n[1] -2.7 -2.2 -1.7 -1.2 -0.7 -0.2 0.3 0.8 1.3<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/seq-function.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-59083\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/seq-function.jpg\" alt=\"seq function - R vector function\" width=\"1366\" height=\"579\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/seq-function.jpg 1366w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/seq-function-150x64.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/seq-function-300x127.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/seq-function-768x326.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/seq-function-1024x434.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/seq-function-520x220.jpg 520w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/a><\/p>\n<p><em><strong>Do you know about <a href=\"https:\/\/data-flair.training\/blogs\/r-numeric-and-character-functions\/\">Numeric and Character Functions in R<\/a><\/strong><\/em><\/p>\n<h3>3. R any() Function<\/h3>\n<p>It takes the set of vectors and returns a set of logical vectors, in which at least one of the value is true.<\/p>\n<h4>3.1. Usage of R any() Function<\/h4>\n<p>Check if any or all the elements of a vector are TRUE. Both functions also accept many objects.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">any(\u2026, na.rm=FALSE)<\/pre>\n<p>Here,<\/p>\n<ul>\n<li><strong>\u2026<\/strong>\u00a0means one or more R objects that need to be checked.<\/li>\n<li><strong>na.rm<\/strong>\u00a0means state whether NA values should be ignored or not.<\/li>\n<\/ul>\n<h3>4. R all() Function<\/h3>\n<p>It takes the set of vectors and returns a set of logical vectors, in which all of the values are TRUE.<\/p>\n<h4>4.1. Usage of R all() Function<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">all(\u2026, na.rm=FALSE)<\/pre>\n<p>Here,<\/p>\n<ul>\n<li><strong>\u2026<\/strong>\u00a0means one or more R objects that need to be checked.<\/li>\n<li><strong>na.rm<\/strong>\u00a0means state whether NA values should be ignored or not.<\/li>\n<\/ul>\n<p>The any() and all() functions are shortcuts because they report any or all of their arguments as TRUE.<\/p>\n<p>Let&#8217;s see this by example:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; #Author DataFlair\r\n&gt; x &lt;- 1:10\r\n&gt; any(x &gt; 5)\r\n[1] TRUE\r\n&gt; any(x &gt; 88)\r\n[1] FALSE\r\n&gt; all(x &gt; 88)\r\n[1] FALSE\r\n&gt; all(x &gt; 0)\r\n[1] TRUE<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/any-and-all-function.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-59084\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/any-and-all-function.jpg\" alt=\"any and all function - R vector function\" width=\"1366\" height=\"535\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/any-and-all-function.jpg 1366w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/any-and-all-function-150x59.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/any-and-all-function-300x117.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/any-and-all-function-768x301.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/any-and-all-function-1024x401.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/any-and-all-function-520x204.jpg 520w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/a><\/p>\n<p>Suppose that R executes the following:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">any(x &gt; 5)<\/pre>\n<p>It first evaluates x &gt; 5:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">(FALSE, FALSE, FALSE, FALSE, FALSE)<\/pre>\n<p><strong>any()<\/strong> function reports whether any of those values are TRUE, while all() function works and reports if all the values are TRUE.<\/p>\n<p><em><strong>Take a deep insight into <a href=\"https:\/\/data-flair.training\/blogs\/r-arguments-introduction\/\">Arguments in R programming<\/a><\/strong><\/em><\/p>\n<h3>R\u2019s C interface<\/h3>\n<p>R\u2019s source code is a powerful technique for improving programming skills. But, many base R functions were already written in C.<\/p>\n<p>R is used to figure out how those functions work. All functions in <a href=\"https:\/\/www.r-project.org\/\">R<\/a> are defined with the prefix,<strong> Rf_ or R_<\/strong>.<\/p>\n<h4>Outline of R\u2019s C interface<\/h4>\n<ul>\n<li>Input validations state about itself so that C function doesn\u2019t crash R.<\/li>\n<li>C data structure shows how to translate data structure names from R to C.<\/li>\n<li>In order to create, change and make vectors in C, we make use Creating and Modifying vectors.<\/li>\n<li>Calling C also defines the functions with the inline package.<\/li>\n<\/ul>\n<h3>Prerequisites to Working on C Interface<\/h3>\n<p>We need a C compiler for C interface. Windows users can use Rtools whereas Mac users will need the Xcode command line tools. And, most Linux distributions will come with the necessary compilers.<\/p>\n<p>In Windows, it is necessary to include the Windows PATH environment variable in it.<\/p>\n<ul>\n<li>Rtools executables directory &#8211; <strong>(C:\\Rtools\\bin)<\/strong><\/li>\n<li>C compiler executables directory &#8211; <strong>(C:\\Rtools\\gcc-4.6.3\\bin)<\/strong><\/li>\n<\/ul>\n<h3>Calling C Functions from R<\/h3>\n<p>Generally, to call a <strong><a href=\"https:\/\/data-flair.training\/blogs\/functions-in-c\/\">C function<\/a>,<\/strong> it requires two pieces:<\/p>\n<ul>\n<li>C function<\/li>\n<li>R wrapper function that uses, Call()<\/li>\n<\/ul>\n<p>We implement our function f(x)= 2x in the file, doubling.c through the following lines of code:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">\/\/ Author DataFlair\r\nvoid doubler(int* mem) {\r\n\u00a0\r\n\u00a0*mem = *mem + *mem;\r\n}<\/pre>\n<p><strong>Code Display:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/void-doubler-C-code.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-59086\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/void-doubler-C-code.jpg\" alt=\"void doubler C code - R Vector Function\" width=\"1299\" height=\"740\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/void-doubler-C-code.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/void-doubler-C-code-150x85.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/void-doubler-C-code-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/void-doubler-C-code-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/void-doubler-C-code-1024x583.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/void-doubler-C-code-520x296.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p>Run the following command in your terminal:<\/p>\n<p>R CMD SHLIB doubling.c<\/p>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Doubling-Command.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-59089\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Doubling-Command.jpg\" alt=\"Doubling Command - R vector function\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Doubling-Command.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Doubling-Command-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Doubling-Command-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Doubling-Command-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Doubling-Command-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/Doubling-Command-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p>On the R interactive session, type:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">#Author DataFlair\r\ndyn.load(\"doubling.so\")\r\n.C(\"doubler\", x = as.integer(5))\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\/09\/dyn-load-R-Code.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-59090\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/dyn-load-R-Code.jpg\" alt=\"dyn load R Code - R vector functions\" width=\"1299\" height=\"713\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/dyn-load-R-Code.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/dyn-load-R-Code-150x82.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/dyn-load-R-Code-300x165.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/dyn-load-R-Code-768x422.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/dyn-load-R-Code-1024x562.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/dyn-load-R-Code-520x285.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<h2>Summary<\/h2>\n<p>We have discussed vectors and functions over the vectors in detail. A vector is a type of datatype and has its own importance. But, using a datatype with function totally changes its meaning and use. We have to develop a code using function only once and you can use that code anytime. There is no need to write code, again and again, as the larger program will store it in two or more functions.<\/p>\n<p>If you have any queries related to R vector functions, let us know in the comment section below.<\/p>\n<p><em><strong>Now, cracking R Interview is easy from these <a href=\"https:\/\/data-flair.training\/blogs\/r-interview-questions-and-answers\/\">R Interview Questions and Answers<\/a><\/strong><\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>We are going to discuss R vector functions in this tutorial. They are the functions that can be applied over R vectors. We will explain all the functions with detailed examples to provide you&#46;&#46;&#46;<\/p>\n","protected":false},"author":6,"featured_media":59105,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[51],"tags":[11194,11195,11274,11277],"class_list":["post-4208","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-r","tag-r-functions","tag-r-functions-on-vectors","tag-r-vector-functions","tag-r-vectors"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>R Vector Functions - How to apply Functions over R Vectors - DataFlair<\/title>\n<meta name=\"description\" content=\"R vector functions tutorial covers all the functions, its examples, R&#039;s C interface and calling C functions from R. R\u00a0vector functions are those functions which we use in R vectors.\" \/>\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-vector-functions\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"R Vector Functions - How to apply Functions over R Vectors - DataFlair\" \/>\n<meta property=\"og:description\" content=\"R vector functions tutorial covers all the functions, its examples, R&#039;s C interface and calling C functions from R. R\u00a0vector functions are those functions which we use in R vectors.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/r-vector-functions\/\" \/>\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-09-18T06:58:59+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-08-25T11:56:59+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/R-Vector-Functions-2.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":"R Vector Functions - How to apply Functions over R Vectors - DataFlair","description":"R vector functions tutorial covers all the functions, its examples, R's C interface and calling C functions from R. R\u00a0vector functions are those functions which we use in R vectors.","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-vector-functions\/","og_locale":"en_US","og_type":"article","og_title":"R Vector Functions - How to apply Functions over R Vectors - DataFlair","og_description":"R vector functions tutorial covers all the functions, its examples, R's C interface and calling C functions from R. R\u00a0vector functions are those functions which we use in R vectors.","og_url":"https:\/\/data-flair.training\/blogs\/r-vector-functions\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2017-09-18T06:58:59+00:00","article_modified_time":"2021-08-25T11:56:59+00:00","og_image":[{"width":802,"height":420,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/R-Vector-Functions-2.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-vector-functions\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/r-vector-functions\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/2c58ecb4f73a39f0ef993f1ddfcd7b89"},"headline":"R Vector Functions &#8211; How to apply Functions over R Vectors","datePublished":"2017-09-18T06:58:59+00:00","dateModified":"2021-08-25T11:56:59+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/r-vector-functions\/"},"wordCount":1061,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/r-vector-functions\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/R-Vector-Functions-2.jpg","keywords":["R functions","R functions on vectors","R Vector functions","R vectors"],"articleSection":["R Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/r-vector-functions\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/r-vector-functions\/","url":"https:\/\/data-flair.training\/blogs\/r-vector-functions\/","name":"R Vector Functions - How to apply Functions over R Vectors - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/r-vector-functions\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/r-vector-functions\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/R-Vector-Functions-2.jpg","datePublished":"2017-09-18T06:58:59+00:00","dateModified":"2021-08-25T11:56:59+00:00","description":"R vector functions tutorial covers all the functions, its examples, R's C interface and calling C functions from R. R\u00a0vector functions are those functions which we use in R vectors.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/r-vector-functions\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/r-vector-functions\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/r-vector-functions\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/R-Vector-Functions-2.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/09\/R-Vector-Functions-2.jpg","width":802,"height":420,"caption":"R Vector Functions"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/r-vector-functions\/#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":"R Vector Functions &#8211; How to apply Functions over R Vectors"}]},{"@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\/4208","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=4208"}],"version-history":[{"count":12,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/4208\/revisions"}],"predecessor-version":[{"id":61723,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/4208\/revisions\/61723"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/59105"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=4208"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=4208"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=4208"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}