3
First of all, what is an Absolute Value?
We can say that the Absolute Value or Module is the same as the distance from a real number to zero, because the module of a real number arose from the need to measure the distance from a negative number to zero. When we measure the distance of any negative number to zero, we realize that the distance becomes negative and as it is not usual to say that a distance or length is negative has been created the real number module that makes the value positive or zero.
Thus, we can say that the module of a real number will follow two conditions:
• The module or absolute value of a real number is the number itself, if it is positive.
• The module or absolute value of a real number will be its symmetric if it is negative.
The Absolute Value is represented by parallel bars and is calculated as follows. Example:
x = |-5| + |-7|
x = √(-5²) + √(-7²)
x = √25 + √49
x = 5 + 7
x = 12
Now that we know what it is and how to calculate the Absolute Value, let us return to the problem applied in R.
Let’s say I have a 6x5 data.frame, for example:
print(Dados)
Linha A B C D E
L1 4 3 -1 2 4
L2 1 -2 1 -5 1
L3 -1 -1 2 3 4
L4 2 4 5 -7 9
But I need to replace the Negative values of the data.frame by the Absolute Value, example:
Linha A B C D E
L1 4 3 1 2 4
L2 1 2 1 5 1
L3 1 1 2 3 4
L4 2 4 5 7 9
How can I replace variables with NEGATIVE values with ABSOLUTE VALUE within my date.?
Dice:
Dados <- read.table(text = "
Linha A B C D E
L1 4 3 -1 2 4
L2 1 -2 1 -5 1
L3 -1 -1 2 3 4
L4 2 4 5 -7 9
", header = TRUE)
You were faster than me. I’m going to erase mine, hahaha. Best solution is that same.
– neves
Hahaha happens : )
– Marcus Nunes
Thank you for the reply Marcus Nunes e neves. I will test.
– Izak Mandrak