Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. x <- c(1.0, 1.2, 1.4, 1.6, 1.6, 1.8, 2.0, 2.6, 2.8, 2.8, 3.0)
  2.  
  3. # change each of the numbers by some value between -3 and 3
  4. # in this case, -3, -2.95, -2.98, -2.97, etc.
  5. changes <- seq(-3, 3, .05)
  6.  
  7. num_tries <- length(changes) * length(x)
  8. i <- seq_len(num_tries)
  9.  
  10. # create a matrix of 11 by all the possible tries
  11. m <- replicate(num_tries, x)
  12. m[cbind(i %% 11 + 1, i)] <- m[cbind(i %% 11 + 1, i)] + rep(changes, each = 11)
  13.  
  14. # remove any containing negatives
  15. m <- m[, colSums(m < 0) == 0]
  16.  
  17. # are there any cases where the mean equals the median?
  18. sum(apply(m, 2, mean) == apply(m, 2, median))
  19. # Result: yes, 1, the one you already found
  20.  
  21. # are there any cases where the mean is less than the median?
  22. sum(apply(m, 2, mean) < apply(m, 2, median))
  23. # Result: no, the answer is 0.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement