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

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

# R program to calculate absolute value
  
# Using abs() method
answer1 <- abs(-12)
answer2 <- abs(21)
answer3 <- abs(-2)
  
print(answer1)
print(answer2)
print(answer3)

chevron_right


Output:

[1] 12
[2] 21
[3] 2

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

[1] 1 2 3 4
[2] 1 2 3 4
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.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.