Skip to content

Instantly share code, notes, and snippets.

@patperu
Created July 7, 2012 11:06
Show Gist options
  • Save patperu/3065896 to your computer and use it in GitHub Desktop.
Save patperu/3065896 to your computer and use it in GitHub Desktop.
Reduce Function
# see ?Reduce
cfrac <- function(x) Reduce(function(u, v) (u / v) + 1, x)
cfrac(c(5, 7))
#[1] 1.714286
#ok
(5/7)+1
#[1] 1.714286
# ok
cfrac(c(5, 7, 8))
#[1] 1.214286
(5/7)+1
# [1] 1.714286
((5/7)+1)/8+1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment