abs

Basics

abs is short for absolute value. It only takes one object as an argument with no optional parameters.


Examples

How do I make all the numbers in my vector positive?

Click to see solution
abs(c(1, 4, -5, 10, -9))
[1] 1 4 5 10 9

In sleep, what is the difference in each student’s amount of sleep?

Click to see solution
abs(sleep$extra)
[1] 0.7 1.6 0.2 1.2 0.1 3.4 3.7 0.8 0.0 2.0 1.9 0.8 1.1 0.1 0.1 4.4 5.5 1.6 4.6 3.4