#' Recursive sequence
#'
#' This takes as input a vector x containing the first three numeric elements of this
#' sequence and a positive integer n denoting the final nth element of the
#' sequence to calculate. The function will return element n.
#'
#' @param x vector
#' @param n integer
#'
#' @return element n
#' @export recurseq1
#'
#' @examples recurseq1(x = c(2, 3, 3), n = 3)
recurseq1 <- function(x, n) {
stopifnot(n > 0 & length(x) == 3)
calcn_v <- vector("numeric", length = n)
for (i in seq_along(calcn_v)) {
if(i <= 3){
calcn_v[i] <- x[i]
}else{
calcn_v[i] <- calcn_v[i-1] + ((calcn_v[i-3] - calcn_v[i-2])/n)
}
}
return(calcn_v[i])
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.