Ana Marija
2021-Oct-14 17:10 UTC
[R] how to do inverse log of every value in every column in data frame
Hi All, I have a data frame like this:> head(b)LRET02 LRET04 LRET06 LRET08 LRET10 LRET12 LRET14 1 0 0.6931472 . 1.0986123 1.0986123 1.0986123 0.6931472 2 2.1972246 2.4849066 2.4849066 . 2.5649494 2.6390573 2.6390573 3 1.6094379 1.7917595 1.6094379 1.7917595 2.0794415 1.9459101 2.0794415 4 0 0 0 0 0 0 0 5 0.6931472 0 1.0986123 1.0986123 0.6931472 0.6931472 0.6931472 6 1.0986123 1.0986123 1.0986123 0.6931472 1.0986123 1.3862944 1.0986123 All values in this data frame are product of natural log. I have to do inverse of it. So for example do do inverse of 0.6931472 I would do:> 2.718281828^0.6931472[1] 2 How do I perform this operation for every single value in this data frame? The original data frame is this dimension:> dim(b)[1] 1441 18 Thanks Ana [[alternative HTML version deleted]]
Richard M. Heiberger
2021-Oct-14 17:16 UTC
[R] [External] how to do inverse log of every value in every column in data frame
> tmp <- data.frame(a=1:3,b=4:6) > exp(tmp)a b 1 2.718282 54.59815 2 7.389056 148.41316 3 20.085537 403.42879> 2.718281828^tmpa b 1 2.718282 54.59815 2 7.389056 148.41316 3 20.085537 403.42879> On Oct 14, 2021, at 13:10, Ana Marija <sokovic.anamarija at gmail.com> wrote: > >> 2.718281828^
Bert Gunter
2021-Oct-14 17:17 UTC
[R] how to do inverse log of every value in every column in data frame
As all of your columns are numeric, you should probably convert your df to a matrix. Then use exp() on that, of course: exp(as.matrix(b)) see ?exp Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Thu, Oct 14, 2021 at 10:10 AM Ana Marija <sokovic.anamarija at gmail.com> wrote:> Hi All, > > I have a data frame like this: > > > head(b) > LRET02 LRET04 LRET06 LRET08 LRET10 LRET12 LRET14 > 1 0 0.6931472 . 1.0986123 1.0986123 1.0986123 0.6931472 > 2 2.1972246 2.4849066 2.4849066 . 2.5649494 2.6390573 2.6390573 > 3 1.6094379 1.7917595 1.6094379 1.7917595 2.0794415 1.9459101 2.0794415 > 4 0 0 0 0 0 0 0 > 5 0.6931472 0 1.0986123 1.0986123 0.6931472 0.6931472 0.6931472 > 6 1.0986123 1.0986123 1.0986123 0.6931472 1.0986123 1.3862944 1.0986123 > > All values in this data frame are product of natural log. I have to do > inverse of it. > So for example do do inverse of 0.6931472 I would do: > > 2.718281828^0.6931472 > [1] 2 > > How do I perform this operation for every single value in this data frame? > > The original data frame is this dimension: > > dim(b) > [1] 1441 18 > > Thanks > Ana > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]