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:
answer1 < - abs ( - 12 )
answer2 < - abs ( 21 )
answer3 < - abs ( - 2 )
print (answer1)
print (answer2)
print (answer3)
|
Output:
[1] 12
[2] 21
[3] 2
Example 2:
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