Open In App

Calculate the absolute value in R programming - abs() method

Last Updated : 10 May, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report
abs() method in R programming is used to get the absolute value that is positive value doesn't change and negative value converted into positive value.
Syntax: abs(value) Return: Returns the absolute value.
Example 1: Python3
# R program to calculate absolute value

# Using abs() method
answer1 <- abs(-12)
answer2 <- abs(21)
answer3 <- abs(-2)

print(answer1)
print(answer2)
print(answer3)
Output:
[1] 12
[2] 21
[3] 2
Example 2: Python3
# R program to calculate absolute value

# Using abs() method
answer1 <- abs(c(1, 2, 3, 4))
answer2 <- abs(c(1, -2, 3, -4))

print(answer1)
print(answer2)
Output:
[1] 1 2 3 4
[2] 1 2 3 4

Next Article
Article Tags :

Similar Reads