Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. foo <- function(n, s = NULL, t = NULL, f = NULL){
  2.  
  3. d <- if(!is.null(t)) t + n else if(!is.null(f)) f^2 + n
  4.  
  5. m <- if(!is.null(s)) s/2 else NULL
  6. r <- if(!is.null(m)) m + 1 else NULL
  7.  
  8. if(!is.null(m) & is.null(m)) d <- m + r
  9.  
  10. out <- data.frame(d)
  11. rownames(out) <- paste0("BB", 1:length(d))
  12. out
  13. }
  14. # Example of use:
  15. foo(n = 30:35, s = 1:2, t = 3:5, f = 7)
  16.  
  17. ## OUTPUT:
  18. d
  19. BB1 33 # add "t" to the rownames of `d`s computed from "t" or "f" for ds computed from "f"
  20. BB2 35
  21. BB3 37
  22. BB4 36
  23. BB5 38
  24. BB6 40
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement