require(ggplot2) # calling "ggplot2" to create graphs ## problem 1 fctrl <- function(n) # making the function to calculate factorials # n = a non-negative integer # NOT calculate other than non-negative integer # out = result of calculation if(n < 0 | n != round(n)){ # Not calculate negative or non-integer numbers print("n must be a non-negative intenger") }else if(n == 0){ # factorial 0 equals 1 return(1) }else{ # otherwise, calculate according to each number result <- 1 # substitution to calculate the function for(i in 1:n){result = result * i # calculate i to previous result for loop } return(result) #return the result } fctrl(-5) # ensure when n is negative fctrl(0) # ensure when n is 0 fctrl(10) == factorial(10) #ensure the function ## problem 2 chs <- function(n, k) {# making the function to calculate combination # argument1 n = non-negative integer # argument2 k = non-negative integer from 0 to n # return value = result if(n