Skip to content
Related Articles

Related Articles

Improve Article

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

  • Last Updated : 05 Jun, 2020

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:




# 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)

Output:

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

Example 2:




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

Output:

[1] 15
[1] -55
[1] 72
My Personal Notes arrow_drop_up
Recommended Articles
Page :