Functions in r
Functions in r
NESTED FUNCTIONS IN R:
• Nested functions in R are functions that are defined within other functions. This feature is useful for structuring code
more efficiently, allowing for encapsulation and reuse of logic within the context of another function.
Example:
In R, functions follow lexical scoping rules. This means that when you refer to a variable inside a
function, R looks for the value of that variable in the environment where the function was created, not
where it was called.
# Global variable
x <- 10
# Function definition
outer_function <- function() {
x <- 20 # Local variable in outer_function
inner_function <- function() {
return(x)
}
return(inner_function()) # OUTPUT : [1] 20
}
# Calling the function
outer_function()
# Global variable
x <- 10
# Function definition
outer_function <- function() {
• R provides the various mathematical functions to perform the mathematical calculation. These
mathematical functions are very helpful to find absolute value, square value and much more
calculations. In R, there are the following functions which are used:
• Basic Arithmetic Functions
• Trigonometric Functions
• Logarithmic and Exponential Functions
• Rounding Functions
• Statistical Functions
• Special Mathematical Functions
• Using Mathematical Constants
THANK YOU