As you have seen, we can apply the abs function to only one column by using the $-sign.

Let’s move on with some calculations…

Example 5: Calculate the Absolute Difference of Two Values

When calculating differences, you might want to know just the absolute difference (not the real difference with a negative value). For this purpose, you can also use the abs function. Let’s first create a data object containing the regular difference of two values:

In this example, we calculated the absolute difference. However, of cause you can calculate the absolute value not only for differences, but also for a correlation, a mean or any other numeric value you can think of.

But there is one restriction…

Example 6: Error in Math.factor(x) : ‘abs’ not meaningful for factors

The application of abs is in general relatively simple. However, a typical error message is the following:

Error in Math.factor(x) : ‘abs’ not meaningful for factors

So why did this error pop up? Usually, because we tried to apply abs to a factor variable. Let’s do an example…

Video Tutorial: Absolute Value Equations

In this R tutorial, we were speaking much about absolute values. However, we did not learn much about the mathematical concept of absolute values. If you want to learn more about the mathematics of absolute values, I can recommend the following YouTube video of the Khan Academy: