Advertisement
Guest User

Untitled

a guest
Mar 17th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. flea_simulate <- function (samples, teleport=FALSE) {
  2. n.samples = length(samples)
  3. flea.position <- runif(1, 0, 100)
  4. flea.positions <- rep(0, n.samples)
  5.  
  6. for (i in 1:n.samples) {
  7. flea.position <- flea.position + samples[i]
  8.  
  9. if (flea.position < 0) {
  10. flea.position <- abs(flea.position)
  11. } else if (flea.position > 100) {
  12. if (teleport) {
  13. flea.position <- flea.position - 100
  14. } else {
  15. flea.position <- 200 - flea.position
  16. }
  17. }
  18.  
  19. flea.positions[i] <- flea.position
  20. }
  21. return(flea.positions)
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement