Get Addition of the Objects passed as Arguments in R Programming – sum() Function

sum() function in R Language is used to return the addition of the values passed as arguments to the function

Syntax: sum(…)

Parameters:
…: numeric or complex or logical vectors

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

# R program to illustrate
# sum function
  
# Creating Vectors
x <- c(10, 20, 30, 40)
y <- c(1.8, 2.4, 3.9)
z <- c(0, -2, 4, -6)
  
# Calling the sum() function
sum(x)  
sum(y)
sum(z)
sum(x, y, z)

chevron_right


Output:

[1] 100
[1] 8.1
[1] -4
[1] 104.1

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# R program to illustrate
# sum function
  
# Calling the sum() function
sum(1:5) # Adding a range
sum(-1:-10)
sum(4:12)

chevron_right


Output:

[1] 15
[1] -55
[1] 72
My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.