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:
# 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
filter_none
Output:
[1] 12 [2] 21 [3] 2
Example 2:
# 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
filter_none
Output:
[1] 1 2 3 4 [2] 1 2 3 4
Recommended Posts:
- Calculate the Median Absolute Deviation in R Programming - mad() Function
- Compute the Natural Logarithm of the Absolute Value of Gamma Function in R Programming - lgamma() Function
- Calculate arc cosine of a value in R programming - acos() function
- Calculate arc tangent of a value in R programming - atan2(y, x) function
- Calculate cosine of a value in R Programming - cos() Function
- Calculate Hyperbolic cosine of a value in R Programming - cosh() Function
- Calculate sine of a value in R Programming - sin() Function
- Calculate Hyperbolic sine of a value in R Programming - sinh() Function
- Calculate Hyperbolic tangent of a value in R Programming - tanh() Function
- Calculate tangent of a value in R Programming - tan() Function
- Calculate Inverse sine of a value in R Programming - asin() Function
- Calculate Inverse cosine of a value in R Programming - acos() Function
- Calculate Inverse tangent of a value in R Programming - atan() Function
- Calculate Factorial of a value in R Programming - factorial() Function
- Calculate nCr value in R Programming - choose() Function
- Convert Character value to ASCII value in R Programming - charToRaw() Function
- Convert Degree value to Radian value in R Programming - deg2rad() Function
- Convert Radian value to Degree value in R Programming - rad2deg() Function
- Absolute and Relative Frequency in R Programming
- Calculate exponential of a number in R Programming - exp() Function
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.

