#' "myseq_n" Function Execution
#'
#' @param x numeric
#' @param n numeric
#'
#' @return
#' @export myseq_n
#'
#' @examples
myseq_n <- function(x,n) {
# error checks
if(!is.numeric(n)){
stop("n needs to be numeric")
}
if(!is.numeric(x)){
stop("x needs to be numeric")
}
if(length(x) != 3){
stop("x must be length 3")
}
if(n < 0){
stop("n must be greater than 0")
}
# scenarios start
# scenario 1: 1 < n < = length(x)
if ((n >= 1) & (n <= length(x) )){
return (x[n])
}
# scenario 2: n < 1
else if (n < 1){
stop("n needs to be greater than zero")
}
# scenario 3: n > length(x)
else {
x_out <- vector(length = n)
x_out[1:3] <- x
for(i in 4:n){
x_out[i] = x_out[i-1] + ((x_out[i-3] - x_out[i-2]) /i)
}
return (x_out[n])
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.