Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Functions for partial factorials, factorials, binomial coeffs., & rows of Pascale's Triangle.
#R version 3.3.2 # # Functions to compute partial factorials, factorials, # binomial coefficients, and rows of Pascale's Triangle. # partfact = function(n,k) { # compute the partial factorial of n to k p=1 for(c in 1:k-1) { p=p*(n-c) } return(p) } fact = function(k) { # compute the factorial of k m=1 if(k>1) { for(i in 2:k) { m=m*i } } return(m) } cat("The factorial of 5 is:\n") fact(5) combin = function(n,k) { # Compute the binary coeff. C(n,k) # Requires functions partfact() and fact() to be defined c = partfact(n,k) / fact(k); print(c); } cat("\nThe number of ways to combine 6 things taken 3 at a time:", combin(6,3)) pascale.row = function(n) { # Compute the Nth row of Pascale's Triangle, where n >= 0 # Requires functions partfact() and fact() to be defined row = seq(0,0,length.out=n+1) row[1]=1 for(i in 1:n+1) { row[i] = partfact(n,i-1) / fact(i-1) } ifelse(n>0,return(row),return(1)) } cat("\n\nRows 2-7 of Pascale's Triangle: \n") pascale.row(2) pascale.row(3) pascale.row(4) pascale.row(5) pascale.row(6) pascale.row(7)
run
|
edit
|
history
|
help
0
Linear and Log linear Model
Dasi
1.second
Example: From 'The R Book' 2nd ed. ~ 2.3.2 Generating Factor Levels...
19-08-2020-JacobiSistema-menos-calc
16-09-2020
Variance Gamma process
ExDecaiEulerMin28-01-21
Arithmetic operations in vector
3dgraphics-and-curvesb