Open In App

Calculating Natural Logarithm of calculated nCr value in R Programming – lchoose() Function

Improve
Improve
Like Article
Like
Save
Share
Report

lchoose() function in R Language is used to return the natural logarithm of nCr value. This function is equal to log(choose(x)).

Syntax: lchoose(n, r)

Parameters:
n: Number of elements
r: Number of combinations

Example 1:




# R program to illustrate
# lchoose function
  
# Calling lchoose() function
answer1 <- lchoose(3, 2)  
answer2 <- lchoose(2, 2)   
answer3 <- lchoose(7, 3
    
print(answer1)  
print(answer2)  
print(answer3)  


Output:

[1] 1.098612
[1] 0
[1] 3.555348

Example 2:




# R program to illustrate
# lchoose function
   
# Calling lchoose() function which 
# is equivalent to log(choose(x))
answer1 <- log(choose(5, 1))  
answer1_2 <- lchoose(5, 1)
answer2 <- log(choose(4, 2))   
answer2_2 <- lchoose(4, 2)
  
# Printing values
print(answer1)  
print(answer1_2)  
print(answer2)  
print(answer2_2)  


Output:

[1] 1.609438
[1] 1.609438
[1] 1.791759
[1] 1.791759

Here, in the above code, the output of log(choose()) and lchoose() are equal which shows that both functions are equivalent.



Last Updated : 08 Jun, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads