I have data in this form:
ds y
1 2015-12-31 51737806366
2 2016-01-01 451800500
3 2016-01-04 48503189
4 2016-01-06 221000
5 2016-01-07 542483038
6 2016-01-08 628189789
7 2016-01-09 556762005
8 2016-01-10 195672447
9 2016-01-11 279202668
10 2016-01-12 540234196
11 2016-01-13 3403591404
12 2016-01-14 610409176
the values on the 'y'
column represent income, money units. I made an exploratory plot of this data in its original form and found the plot not too useful, the visual of the data was not appropriate, so in order to improve my visualizations I applied a log2()
transformation to the 'y'
column... it worked fine:
ds y
1 2015-12-31 35.59050
2 2016-01-01 28.75111
3 2016-01-04 25.53158
4 2016-01-06 17.75369
5 2016-01-07 29.01500
6 2016-01-08 29.22663
7 2016-01-09 29.05249
8 2016-01-10 27.54387
9 2016-01-11 28.05674
10 2016-01-12 29.00901
11 2016-01-13 31.66441
The problem now is that in order to complete my analysis I need to get the 'y'
values back to their original form. Is there anyway or implicit R
function to reverse the log2()
transformation I applied so I can get the original numbers back?
To rid an equation of logarithms, raise both sides to the same exponent as the base of the logarithms.
Exponential transformation (inverse of log transformation)
An inverse log transformation in the R programming language can be exp(x) and expm1(x) functions. exp( ) function simply computes the exponential function, whereas the expm1( ) function computes exp(x) – 1 accurately also for |x| << 1.
It's simple.
First, call log2:
data$y = log2(data$y)
After that, if you want to have the original y back just do:
data$y = 2^data$y
The logarithm is the inverse function to exponentiation.
The general rule is:
logb(x) = y as by = x
For instance:
log2(4) = 2 as 22 = 4
log2(8) = 3 as 23 = 8
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With