R programming: How do I get Euler's number?

REulers Number

R Problem Overview


For example, how would I go about entering the value e^2 in R?

R Solutions


Solution 1 - R

The R expression

exp(1)

represents e, and

exp(2)

represents e^2.

This works because exp is the exponentiation function with base e.

Solution 2 - R

-digamma(1) is the Euler's Constant in R.

e, (exp(1) in R), which is the natural base of the natural logarithm

Euler's Constant. Euler's Number

Solution 3 - R

if you want to have a little number e to play with, you can also make one yourself:

    emake <- function(){
        options("warn"=-1)
        e <- 0
        for (n in 0:2000){
	        e <- e+ 1/(factorial(n))
        }
        return(e)
    }
    e <- emake()
    e^10
    exp(10)
    
    # or even:
    e <- sum(1/factorial(0:100)) 

fun stuff

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTravisView Question on Stackoverflow
Solution 1 - RAdam MihalcinView Answer on Stackoverflow
Solution 2 - ROldyoungView Answer on Stackoverflow
Solution 3 - Rtim riffeView Answer on Stackoverflow