<?xml version="1.0" encoding='utf-8'?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<card id="card1" title="R (programming language) - Page 23 - Wikipedia">
<p>
<a accesskey="1" href="page.php?w=R_(programming_language)&amp;p=22">1.Previous</a><br />
<a accesskey="3" href="page.php?w=R_%28programming_language%29&amp;p=24">3.Next</a>
</p>
<p>are <a href="page.php?w=closure_%28computer_programming%29">closures</a>.</p>

<p>The following is an example of creating a function to perform an arithmetic calculation:<syntaxhighlight lang="r"># The function's input parameters are x and y.<br/>
# The function, named f, returns a linear combination of x and y.f <- function(x, y) {  z <- 3 * x + 4 * y</p>

<p>  # An explicit return() statement is optional--it could be replaced with simply `z` in this case.  return(z)}</p>

<p>
# As an alternative, the last statement executed in a function is returned implicitly.f <- function(x, y) 3 * x + 4 * y</syntaxhighlight></-></p>

<p>The following is some output from using the function defined above:<syntaxhighlight lang="rout">> f(1, 2) #  3 * 1 + 4 * 2 = 3 + 8[1] 11</syntaxhighlight></p>

<p>> f(c(1, 2, 3), c(5, 3, 4)) # Element-wise calculation[1] 23 18 25</p>

<p>> f(1:3, 4) # Equivalent to f(c(1, 2, 3), c(4, 4, 4))[1] 19 22 25</p></-></syntaxhighlight></p><p>
<a accesskey="1" href="page.php?w=R_(programming_language)&amp;p=22">1.Previous</a><br />
<a accesskey="3" href="page.php?w=R_%28programming_language%29&amp;p=24">3.Next</a>
</p>

<do type="prev" label="Search">
        <go href="search.wml"/>
</do>

</card>
</wml>
