R Programming abs - Syntax
mixed abs(mixed n);
The abs() function in R Programming is used to return the absolute value or modulus |x| of a real number x is the non-negative value of x without regard to its sign.
mixed abs(mixed n);
mixed n |
Specifies the real number (int, long, float, double) / infinity (*Required) |
---|---|
Return mixed |
Returns a number / infinity respective to an input argument. |
Convert the positive and negative integer to an absolute value.
# Positive integer value
n <- abs(9)
print(paste("The absolute value of 9 is ", n));
# Negative integer value
x <- abs(-6)
print(paste("The absolute value of -6 is ", x));
Convert the positive and negative float to an absolute value.
# Positive floating point value
n <- abs(9.3)
print(paste("The absolute value of 9.3 is ", n));
# Negative floating point value
x <- abs(-6.3)
print(paste("The absolute value of -6.3 is ", x))
Convert the positive and negative Infinity to an absolute value.
# Positive ∞ infinite value
n <- abs(Inf)
print(paste("The absolute value of Inf is ", n));
# Negative ∞ infinite value
x <- abs(-Inf)
print(paste("The absolute value of -Inf is ", x))