Martin Møller Skarbiniks Pedersen
2019-Oct-27 23:01 UTC
[R] Conversion from python to R - log-problem
Hi, I am trying to convert a small python computation to R but my R version gets the wrong result. The python code: import math import log x = log(2) for i in range(3,7): x = log(i)**x print(x) 3.14157738716919 My R-version: x <- log10(2) for (i in 3:6) { x <- log10(i)**x } print(x) [1] 0.8207096 range(3,7) (Python) is the same as 3:6 (R) log() (Python) is the same as log10 (R) What can be wrong? Regards Martin M. S. Pedersen ps. I hope this is plain text without any HTML. [[alternative HTML version deleted]]
On 27/10/2019 7:01 p.m., Martin M?ller Skarbiniks Pedersen wrote:> Hi, > I am trying to convert a small python computation to R but my R version > gets the wrong result.You are using log10() in R, when you should be using log().> > The python code: > import math import log > x = log(2) > for i in range(3,7): > x = log(i)**x > print(x) > 3.14157738716919 > > My R-version: > x <- log10(2) > for (i in 3:6) { > x <- log10(i)**x > } > print(x) > [1] 0.8207096 > > > > range(3,7) (Python) is the same as 3:6 (R) > log() (Python) is the same as log10 (R) > > What can be wrong? > > Regards > Martin M. S. Pedersen > > ps. I hope this is plain text without any HTML.Nope! But it was readable anyway.> > [[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. >