How to find the inverse of log10 for an R data frame column?


To find the log10 of a data frame column then log10 function will be used but to find the inverse of the log10 can be found by putting 10 raises to the power of the log10 column. For example, if we have a data frame called df that contains a column x then the log10 will be found by using

log10(df$x)

after that the inverse will be found by using 10^(df$x).

Example1

Consider the below data frame −

Live Demo

> x1<-sample(10000:99999,20)
> x2<-rpois(20,2)
> df1<-data.frame(x1,x2)
> df1

Output

      x1 x2
1  66210  2
2  42033  2
3  39309  2
4  80353  3
5  92864  2
6  48621  2
7  32400  1
8  55566  2
9  85535  5
10 57837  2
11 48539  1
12 29255  1
13 19305  1
14 54891  4
15 69511  3
16 35786  5
17 74461  0
18 23754  3
19 78146  1
20 16219  1

Finding the log10 of x1 column −

> df1$x1<-log10(df1$x1)
> df1

Output

         x1 x2
1  4.820924  2
2  4.623590  2
3  4.594492  2
4  4.905002  3
5  4.967847  2
6  4.686824  2
7  4.510545  1
8  4.744809  2
9  4.932144  5
10 4.762206  2
11 4.686091  1
12 4.466200  1
13 4.285670  1
14 4.739501  4
15 4.842054  3
16 4.553713  5
17 4.871929  0
18 4.375737  3
19 4.892907  1
20 4.210024  1

Finding the inverse of column x1 −

> df1$x1<-10^(df1$x1)
> df1

Output

      x1 x2
1  66210  2
2  42033  2
3  39309  2
4  80353  3
5  92864  2
6  48621  2
7  32400  1
8  55566  2
9  85535  5
10 57837  2
11 48539  1
12 29255  1
13 19305  1
14 54891  4
15 69511  3
16 35786  5
17 74461  0
18 23754  3
19 78146  1
20 16219  1

Example2

Live Demo

> y1<-1:20
> y2<-sample(1000000:9999999,20)
> df2<-data.frame(y1,y2)
> df2

Output

   y1      y2 1   1 7038766 2   2 1814441 3   3 7484636 4   4 3937342 5   5 4650626 6   6 2436222 7   7 9931589 8   8 2567213 9   9 2207442 10 10 5339350 11 11 4079052 12 12 8869255 13 13 1573860 14 14 9458496 15 15 8710227 16 16 2636125 17 17 4632768 18 18 4402171 19 19 1756356 20 20 5951907

Finding the log10 of y2 column −

> df2$y2<-log10(df2$y2)
> df2

Output

   y1       y2
1   1 6.847497
2   2 6.258743
3   3 6.874171
4   4 6.595203
5   5 6.667511
6   6 6.386717
7   7 6.997019
8   8 6.409462
9   9 6.343889
10 10 6.727488
11 11 6.610559
12 12 6.947887
13 13 6.196966
14 14 6.975822
15 15 6.940029
16 16 6.420966
17 17 6.665841
18 18 6.643667
19 19 6.244613
20 20 6.774656

Finding the inverse of column y2 −

> df2$y2<-10^(df2$y2)
> df2

Output

   y1      y2
1   1 7038766
2   2 1814441
3   3 7484636
4   4 3937342
5   5 4650626
6   6 2436222
7   7 9931589
8   8 2567213
9   9 2207442
10 10 5339350
11 11 4079052
12 12 8869255
13 13 1573860
14 14 9458496
15 15 8710227
16 16 2636125
17 17 4632768
18 18 4402171
19 19 1756356
20 20 5951907

Updated on: 05-Mar-2021

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements