Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- x <- c(1.0, 1.2, 1.4, 1.6, 1.6, 1.8, 2.0, 2.6, 2.8, 2.8, 3.0)
- # change each of the numbers by some value between -3 and 3
- # in this case, -3, -2.95, -2.98, -2.97, etc.
- changes <- seq(-3, 3, .05)
- num_tries <- length(changes) * length(x)
- i <- seq_len(num_tries)
- # create a matrix of 11 by all the possible tries
- m <- replicate(num_tries, x)
- m[cbind(i %% 11 + 1, i)] <- m[cbind(i %% 11 + 1, i)] + rep(changes, each = 11)
- # remove any containing negatives
- m <- m[, colSums(m < 0) == 0]
- # are there any cases where the mean equals the median?
- sum(apply(m, 2, mean) == apply(m, 2, median))
- # Result: yes, 1, the one you already found
- # are there any cases where the mean is less than the median?
- sum(apply(m, 2, mean) < apply(m, 2, median))
- # Result: no, the answer is 0.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement