Home Python C Language C ++ HTML 5 CSS Javascript Java Kotlin SQL DJango Bootstrap React.js R C# PHP ASP.Net Numpy Dart Pandas Digital Marketing

R Functions


In R, a function is like a recipe. You define a set of instructions for the computer to follow, and then you can use those instructions whenever you want without having to repeat yourself. Let's break it down with an example of a simple function that adds two numbers:

Example

# Define a function called add_numbers
add_numbers <- function(x, y) {
result <- x + y # Add the two numbers
return(result) # Return the result
}

# Now let's use the function
sum_result <- add_numbers(3, 5)
print(sum_result) # Output: 8

Here's what's happening:

So, a function is a way to bundle up a set of instructions so that you can reuse them whenever needed, making your code more organized and efficient.


Advertisement





Q3 Schools : India


Online Complier

HTML 5

Python

java

C++

C

JavaScript

Website Development

HTML

CSS

JavaScript

Python

SQL

Campus Learning

C

C#

java