YouTip LogoYouTip

R Func Exp

# R exp() Function - Calculate Exponential [![Image 3: R Language Examples](https://example.com/images/up.gif) R Language Examples](https://example.com/r/r-examples.html) The R exp() function is used to calculate the x-th power of e, i.e., the natural exponential function. exp() is the inverse operation of the natural logarithm log(), and is widely used in scenarios such as exponential growth models and logistic regression. The exp() function syntax is as follows: exp(x) **Parameter Description:** * **x** Input numeric value or numeric vector. ## Example # Calculate the power of e print(exp(1))# e^1 = e print(exp(2))# e^2 print(exp(0))# e^0 = 1 # Vector operation x <-c(0, 1, 2, 3) result.exp<-exp(x) print(result.exp) # exp and log are inverse operations print(exp(log(5)))# e^(ln(5)) = 5 print(log(exp(5)))# ln(e^5) = 5 Executing the above code outputs: 2.718282 7.389056 1 1.000000 2.718282 7.389056 20.085537 5 5 exp() is commonly used to convert log-odds back to probabilities: ## Example # Log-odds in logistic regression log_odds <-c(-2, -1, 0, 1, 2) # Convert log-odds to probability # Probability = exp(log_odds) / (1 + exp(log_odds)) prob <-exp(log_odds)/(1+exp(log_odds)) print(round(prob, 4)) Executing the above code outputs: 0.1192 0.2689 0.5000 0.7311 0.8808 [![Image 4: R Language Examples](https://example.com/images/up.gif) R Language Examples](https://example.com/r/r-examples.html)
← R Func FactorialR Func Dim β†’