SHARE
TWEET

Untitled

a guest Feb 22nd, 2019 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #' Sum values with n = n + 1 in difference
  2.  
  3. recursive <- function(x){
  4.   if(x==1){
  5.     return(1)
  6.   } else {
  7.     x + recursive(x-1)
  8.   }
  9. }
  10.  
  11. recursive <- Vectorize(recursive)
  12.  
  13. recursive(1:100)
  14.  
  15. #' Factorial function
  16. factorial_this <- function(x){
  17.   if(x==1){
  18.     return(1)
  19.   } else {
  20.     x * factorial_this(x-1)
  21.   }
  22. }
  23.  
  24. factorial_this(10)
  25. factorial(10)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top