[R] Conversion from python to R - log-problem

Duncan Murdoch murdoch@dunc@n @end|ng |rom gm@||@com
Mon Oct 28 00:15:43 CET 2019


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 using 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.
>



More information about the R-help mailing list