Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.34 KB | None | 0 0
  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)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement